JetStream
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
strtk.hpp
Go to the documentation of this file.
1 /*
2  *****************************************************************
3  * String Toolkit Library *
4  * *
5  * Author: Arash Partow (2002-2013) *
6  * URL: http://www.partow.net/programming/strtk/index.html *
7  * *
8  * Copyright notice: *
9  * Free use of the String Toolkit Library is permitted under the *
10  * guidelines and in accordance with the most current version of *
11  * the Common Public License. *
12  * http://www.opensource.org/licenses/cpl1.0.php *
13  * *
14  *****************************************************************
15 */
16 
17 #ifndef INCLUDE_STRTK_HPP
18 #define INCLUDE_STRTK_HPP
19 
20 
21 #include <cstddef>
22 #include <cctype>
23 #include <cstring>
24 #include <cerrno>
25 #include <exception>
26 #include <cmath>
27 #include <iterator>
28 #include <limits>
29 #include <iostream>
30 #include <fstream>
31 #include <sstream>
32 #include <utility>
33 #include <algorithm>
34 #include <string>
35 #include <vector>
36 #include <deque>
37 #include <list>
38 #include <set>
39 #include <map>
40 #include <stack>
41 #include <queue>
42 
43 
44 #ifndef strtk_no_tr1_or_boost
45  #define strtk_enable_lexical_cast
46  #define strtk_enable_random
47  #define strtk_enable_regex
48 #endif
49 
50 #ifdef strtk_enable_lexical_cast
51  #include <boost/lexical_cast.hpp>
52 #endif
53 
54 #ifdef strtk_enable_random
55  // Requires definition of a TR1 compatible random library header
56  //#include <random>
57  #include <boost/random.hpp>
58 #endif
59 
60 #ifdef strtk_enable_regex
61  // Requires definition of a TR1 compatible regex library header
62  //#include <regex>
63  #include <boost/regex.hpp>
64 #endif
65 
66 
67 namespace strtk
68 {
69 
70  static const std::size_t one_kilobyte = 1024;
71  static const std::size_t one_megabyte = 1024 * one_kilobyte;
72  static const std::size_t one_gigabyte = 1024 * one_megabyte;
73  static const std::size_t magic_seed = 0xA5A5A5A5;
74 
75  template <typename Tokenizer, typename Function>
76  inline std::size_t for_each_token(const std::string& buffer,
77  Tokenizer& tokenizer,
78  Function function)
79  {
80  std::size_t token_count = 0;
81  tokenizer.assign(buffer);
82  typename Tokenizer::iterator itr = tokenizer.begin();
83  typename Tokenizer::const_iterator end = tokenizer.end();
84  while (end != itr)
85  {
86  function(*itr);
87  ++itr;
88  ++token_count;
89  }
90  return token_count;
91  }
92 
93  template <typename Function>
94  inline std::size_t for_each_line(std::istream& stream,
95  Function function,
96  const std::size_t& buffer_size = one_kilobyte)
97  {
98  std::string buffer;
99  buffer.reserve(buffer_size);
100  std::size_t line_count = 0;
101  while (std::getline(stream,buffer))
102  {
103  function(buffer);
104  ++line_count;
105  }
106  return line_count;
107  }
108 
109  template <typename Function>
110  inline std::size_t for_each_line_n(std::istream& stream,
111  const std::size_t& n,
112  Function function,
113  const std::size_t& buffer_size = one_kilobyte)
114  {
115  std::string buffer;
116  buffer.reserve(buffer_size);
117  std::size_t line_count = 0;
118  while (std::getline(stream,buffer))
119  {
120  function(buffer);
121  if (n == ++line_count)
122  break;
123  }
124  return line_count;
125  }
126 
127  template <typename Function>
128  inline std::size_t for_each_line(const std::string& file_name,
129  Function function,
130  const std::size_t& buffer_size = one_kilobyte)
131  {
132  std::ifstream stream(file_name.c_str());
133  if (stream)
134  return for_each_line(stream,function,buffer_size);
135  else
136  return 0;
137  }
138 
139  template <typename Function>
140  inline std::size_t for_each_line_n(const std::string& file_name,
141  const std::size_t& n,
142  Function function,
143  const std::size_t& buffer_size = one_kilobyte)
144  {
145  std::ifstream stream(file_name.c_str());
146  if (stream)
147  return for_each_line_n(stream,n,function,buffer_size);
148  else
149  return 0;
150  }
151 
152  template <typename Function>
153  inline std::size_t for_each_line_conditional(std::istream& stream,
154  Function function,
155  const std::size_t& buffer_size = one_kilobyte)
156  {
157  std::string buffer;
158  buffer.reserve(buffer_size);
159  std::size_t line_count = 0;
160  while (std::getline(stream,buffer))
161  {
162  if (!function(buffer))
163  {
164  return line_count;
165  }
166  ++line_count;
167  }
168  return line_count;
169  }
170 
171  template <typename Function>
172  inline std::size_t for_each_line_n_conditional(std::istream& stream,
173  const std::size_t& n,
174  Function function,
175  const std::size_t& buffer_size = one_kilobyte)
176  {
177  std::string buffer;
178  buffer.reserve(buffer_size);
179  std::size_t line_count = 0;
180  while (std::getline(stream,buffer))
181  {
182  if (!function(buffer))
183  {
184  return line_count;
185  }
186  if (n == ++line_count)
187  break;
188  }
189  return line_count;
190  }
191 
192  template <typename Function>
193  inline std::size_t for_each_line_conditional(const std::string& file_name,
194  Function function,
195  const std::size_t& buffer_size = one_kilobyte)
196  {
197  std::ifstream stream(file_name.c_str());
198  if (stream)
199  return for_each_line_conditional(stream,function,buffer_size);
200  else
201  return 0;
202  }
203 
204  template <typename Function>
205  inline std::size_t for_each_line_n_conditional(const std::string& file_name,
206  const std::size_t& n,
207  Function function,
208  const std::size_t& buffer_size = one_kilobyte)
209  {
210  std::ifstream stream(file_name.c_str());
211  if (stream)
212  return for_each_line_n_conditional(stream,n,function,buffer_size);
213  else
214  return 0;
215  }
216 
217  template <typename T>
218  inline bool read_line_as_value(std::istream& stream,
219  T& t,
220  const std::size_t& buffer_size = one_kilobyte)
221  {
222  std::string buffer;
223  buffer.reserve(buffer_size);
224  if (!std::getline(stream,buffer))
225  return false;
226  return string_to_type_converter(buffer,t);
227  }
228 
229  namespace details
230  {
232  struct unsigned_type_tag {};
233  struct signed_type_tag {};
234  struct real_type_tag {};
235  struct byte_type_tag {};
236  struct bool_type_tag {};
239  struct base64_type_tag {};
243  struct value_type_tag {};
244  struct sink_type_tag {};
245  struct stl_seq_type_tag {};
248  struct expect_type_tag {};
249  struct like_type_tag {};
250  struct inrange_type_tag {};
251  struct trim_type_tag {};
252  struct lcase_type_tag {};
253  struct ucase_type_tag {};
255 
256  template <typename T>
258  {
260  };
261 
262  template <typename T>
264  {
266  };
267 
268  template <bool, typename T = void>
269  struct enable_if {};
270 
271  template <typename T>
272  struct enable_if<true, T> { typedef T type; };
273 
274  template <typename T>
276  {
277  enum { value = false };
278  };
279 
280  template <typename T>
282  {
284  };
285 
286  template <typename T> struct numeric;
287  template <typename T> inline std::size_t type_length(const T&);
288 
289  struct no_t {};
290  struct yes_t {};
291 
292  template <typename T>
293  struct is_pod
294  {
295  typedef no_t result_t;
296  enum { result = false };
297  };
298 
299  template <typename T>
301  { typedef no_t result_t; };
302 
303  #define register_stl_container1(C) \
304  template <typename T1, typename T2>struct is_stl_container<C<T1,T2> >{ typedef yes_t result_t; };
305 
306  #define register_stl_container2(C) \
307  template <typename T1, typename T2, typename T3>struct is_stl_container<C<T1,T2,T3> >{ typedef yes_t result_t; };
308 
309  register_stl_container1(std::vector)
310  register_stl_container1(std::deque)
311  register_stl_container1(std::list)
312  register_stl_container1(std::queue)
313  register_stl_container1(std::stack)
314  register_stl_container2(std::set)
315  register_stl_container2(std::multiset)
316  register_stl_container2(std::priority_queue)
317 
318  #undef register_stl_container1
319  #undef register_stl_container2
320 
321  } // namespace details
322 
323  template <typename Iterator, typename T>
324  inline bool string_to_type_converter(const Iterator begin, const Iterator end, T& t)
325  {
326  typedef typename details::is_valid_iterator<Iterator>::type itr_type;
328  Iterator itr = begin;
329  return string_to_type_converter_impl(itr,end,t,type);
330  }
331 
332  template <typename Iterator, typename T>
333  inline bool string_to_type_converter(const std::pair<Iterator,Iterator>& range, T& t)
334  {
335  return string_to_type_converter(range.first,range.second,t);
336  }
337 
338  template <typename T, typename Iterator>
339  inline T string_to_type_converter(const Iterator begin, const Iterator end)
340  {
341  typedef typename details::is_valid_iterator<Iterator>::type itr_type;
343  T t;
344  Iterator itr = begin;
345  if (string_to_type_converter_impl(itr,end,t,type))
346  return t;
347  else
348  throw std::invalid_argument("string_to_type_converter() - Failed to convert: " +
349  std::string(begin,end));
350  }
351 
352  template <typename T, typename Iterator>
353  inline T string_to_type_converter(const std::pair<Iterator,Iterator>& range)
354  {
355  return string_to_type_converter<T>(range.first,range.second);
356  }
357 
358  template <typename T>
359  inline bool string_to_type_converter(const std::string& s, T& t)
360  {
361  return string_to_type_converter<const char*,T>(s.data(),s.data() + s.size(),t);
362  }
363 
364  template <typename T>
366  {
367  return string_to_type_converter<T>(s.data(),s.data() + s.size());
368  }
369 
370  template <typename T>
371  inline bool type_to_string(const T& t, std::string& s)
372  {
374  return type_to_string_converter_impl(t,s,type);
375  }
376 
377  template <typename T>
378  inline std::string type_to_string(const T& t)
379  {
380  std::string s;
381  if (type_to_string<T>(t,s))
382  return s;
383  else
384  throw std::invalid_argument("type_to_string() - Failed to convert type to string");
385  }
386 
387  #define strtk_begin_register_string_to_type \
388  namespace strtk { namespace details {
389 
390  #define strtk_end_register_string_to_type \
391  }}
392 
393  #define strtk_string_to_type_begin(Type) \
394  namespace strtk { namespace details { template <typename Iterator> \
395  inline bool string_to_type_converter_impl(const Iterator& begin, const Iterator& end, \
396  Type& t, details::not_supported_type_tag&) {
397 
398  #define strtk_string_to_type_end()\
399  }}}
400 
401  template <typename T,
402  typename Allocator,
403  template <typename,typename> class Sequence>
404  inline std::size_t load_from_text_file(std::istream& stream,
405  Sequence<T,Allocator>& sequence,
406  const std::size_t& buffer_size = one_kilobyte)
407  {
408  if (!stream) return 0;
409  std::string buffer;
410  buffer.reserve(buffer_size);
411  std::size_t line_count = 0;
412  while (std::getline(stream,buffer))
413  {
414  ++line_count;
415  sequence.push_back(string_to_type_converter<T>(buffer));
416  }
417  return line_count;
418  }
419 
420  template <typename T,
421  typename Comparator,
422  typename Allocator>
423  inline std::size_t load_from_text_file(std::istream& stream,
424  std::set<T,Comparator,Allocator>& set,
425  const std::size_t& buffer_size = one_kilobyte)
426  {
427  if (!stream) return 0;
428  std::string buffer;
429  buffer.reserve(buffer_size);
430  std::size_t line_count = 0;
431  while (std::getline(stream,buffer))
432  {
433  ++line_count;
434  set.insert(string_to_type_converter<T>(buffer));
435  }
436  return line_count;
437  }
438 
439  template <typename T,
440  typename Comparator,
441  typename Allocator>
442  inline std::size_t load_from_text_file(std::istream& stream,
443  std::multiset<T,Comparator,Allocator>& multiset,
444  const std::size_t& buffer_size = one_kilobyte)
445  {
446  if (!stream) return 0;
447  std::string buffer;
448  buffer.reserve(buffer_size);
449  std::size_t line_count = 0;
450  while (std::getline(stream,buffer))
451  {
452  ++line_count;
453  multiset.insert(string_to_type_converter<T>(buffer));
454  }
455  return line_count;
456  }
457 
458  template <typename T, typename Container>
459  inline std::size_t load_from_text_file(std::istream& stream,
460  std::queue<T,Container>& queue,
461  const std::size_t& buffer_size = one_kilobyte)
462  {
463  if (!stream) return 0;
464  std::string buffer;
465  buffer.reserve(buffer_size);
466  std::size_t line_count = 0;
467  while (std::getline(stream,buffer))
468  {
469  ++line_count;
470  queue.push(string_to_type_converter<T>(buffer));
471  }
472  return line_count;
473  }
474 
475  template <typename T, typename Container>
476  inline std::size_t load_from_text_file(std::istream& stream,
477  std::stack<T,Container>& stack,
478  const std::size_t& buffer_size = one_kilobyte)
479  {
480  if (!stream) return 0;
481  std::string buffer;
482  buffer.reserve(buffer_size);
483  std::size_t line_count = 0;
484  while (std::getline(stream,buffer))
485  {
486  ++line_count;
487  stack.push(string_to_type_converter<T>(buffer));
488  }
489  return line_count;
490  }
491 
492  template <typename T,
493  typename Container,
494  typename Comparator>
495  inline std::size_t load_from_text_file(std::istream& stream,
496  std::priority_queue<T,Container,Comparator>& priority_queue,
497  const std::size_t& buffer_size = one_kilobyte)
498  {
499  if (!stream) return 0;
500  std::string buffer;
501  buffer.reserve(buffer_size);
502  std::size_t line_count = 0;
503  while (std::getline(stream,buffer))
504  {
505  ++line_count;
506  priority_queue.push(string_to_type_converter<T>(buffer));
507  }
508  return line_count;
509  }
510 
511  template <typename T,
512  typename Allocator,
513  template <typename,typename> class Sequence>
514  inline std::size_t load_from_text_file(const std::string& file_name,
515  Sequence<T,Allocator>& sequence,
516  const std::size_t& buffer_size = one_kilobyte)
517  {
518  std::ifstream stream(file_name.c_str());
519  if (!stream)
520  return 0;
521  else
522  return load_from_text_file(stream,sequence,buffer_size);
523  }
524 
525  template <typename T,
526  typename Comparator,
527  typename Allocator>
528  inline std::size_t load_from_text_file(const std::string& file_name,
529  std::set<T,Comparator,Allocator>& set,
530  const std::size_t& buffer_size = one_kilobyte)
531  {
532  std::ifstream stream(file_name.c_str());
533  if (!stream)
534  return 0;
535  else
536  return load_from_text_file(stream,set,buffer_size);
537  }
538 
539  template <typename T,
540  typename Comparator,
541  typename Allocator>
542  inline std::size_t load_from_text_file(const std::string& file_name,
543  std::multiset<T,Comparator,Allocator>& multiset,
544  const std::size_t& buffer_size = one_kilobyte)
545  {
546  std::ifstream stream(file_name.c_str());
547  if (!stream)
548  return 0;
549  else
550  return load_from_text_file(stream,multiset,buffer_size);
551  }
552 
553  template <typename T, typename Container>
554  inline std::size_t load_from_text_file(const std::string& file_name,
555  std::queue<T,Container>& queue,
556  const std::size_t& buffer_size = one_kilobyte)
557  {
558  std::ifstream stream(file_name.c_str());
559  if (!stream)
560  return 0;
561  else
562  return load_from_text_file(stream,queue,buffer_size);
563  }
564 
565  template <typename T, typename Container>
566  inline std::size_t load_from_text_file(const std::string& file_name,
567  std::stack<T,Container>& stack,
568  const std::size_t& buffer_size = one_kilobyte)
569  {
570  std::ifstream stream(file_name.c_str());
571  if (!stream)
572  return 0;
573  else
574  return load_from_text_file(stream,stack,buffer_size);
575  }
576 
577  template <typename T,
578  typename Container,
579  typename Comparator>
580  inline std::size_t load_from_text_file(const std::string& file_name,
581  std::priority_queue<T,Container,Comparator>& priority_queue,
582  const std::size_t& buffer_size = one_kilobyte)
583  {
584  std::ifstream stream(file_name.c_str());
585  if (!stream)
586  return 0;
587  else
588  return load_from_text_file(stream,priority_queue,buffer_size);
589  }
590 
591  template <typename T,
592  typename Allocator,
593  template <typename,typename> class Sequence>
594  inline std::size_t write_to_text_file(std::ostream& stream,
595  const Sequence<T,Allocator>& sequence,
596  const std::string& delimiter = "")
597  {
598  if (!stream) return 0;
599 
600  std::size_t count = 0;
601  typename Sequence<T,Allocator>::const_iterator itr = sequence.begin();
602  typename Sequence<T,Allocator>::const_iterator end = sequence.end();
603 
604  if (!delimiter.empty())
605  {
606  while (end != itr)
607  {
608  stream << (*itr) << delimiter;
609  ++itr;
610  ++count;
611  }
612  }
613  else
614  {
615  while (end != itr)
616  {
617  stream << (*itr);
618  ++itr;
619  ++count;
620  }
621  }
622  return count;
623  }
624 
625  template <typename T,
626  typename Comparator,
627  typename Allocator>
628  inline std::size_t write_to_text_file(std::ostream& stream,
629  const std::set<T,Comparator,Allocator>& set,
630  const std::string& delimiter = "")
631  {
632  if (!stream) return 0;
633 
634  std::size_t count = 0;
635  typename std::set<T,Comparator,Allocator>::const_iterator itr = set.begin();
636  typename std::set<T,Comparator,Allocator>::const_iterator end = set.end();
637 
638  if (!delimiter.empty())
639  {
640  while (end != itr)
641  {
642  stream << (*itr) << delimiter;
643  ++itr;
644  ++count;
645  }
646  }
647  else
648  {
649  while (end != itr)
650  {
651  stream << (*itr);
652  ++itr;
653  ++count;
654  }
655  }
656  return count;
657  }
658 
659  template <typename T,
660  typename Comparator,
661  typename Allocator>
662  inline std::size_t write_to_text_file(std::ostream& stream,
663  const std::multiset<T,Comparator,Allocator>& multiset,
664  const std::string& delimiter = "")
665  {
666  if (!stream) return 0;
667 
668  std::size_t count = 0;
669  typename std::multiset<T,Comparator,Allocator>::const_iterator itr = multiset.begin();
670  typename std::multiset<T,Comparator,Allocator>::const_iterator end = multiset.end();
671 
672  if (!delimiter.empty())
673  {
674  while (end != itr)
675  {
676  stream << (*itr) << delimiter;
677  ++itr;
678  ++count;
679  }
680  }
681  else
682  {
683  while (end != itr)
684  {
685  stream << (*itr);
686  ++itr;
687  ++count;
688  }
689  }
690  return count;
691  }
692 
693  template <typename T,
694  typename Allocator,
695  template <typename,typename> class Sequence>
696  inline std::size_t write_to_text_file(const std::string& file_name,
697  const Sequence<T,Allocator>& sequence,
698  const std::string& delimiter = "")
699  {
700  std::ofstream stream(file_name.c_str());
701  if (!stream)
702  return 0;
703  else
704  return write_to_text_file(stream,sequence,delimiter);
705  }
706 
707  template <typename T,
708  typename Comparator,
709  typename Allocator>
710  inline std::size_t write_to_text_file(const std::string& file_name,
711  const std::set<T,Comparator,Allocator>& set,
712  const std::string& delimiter = "")
713  {
714  std::ofstream stream(file_name.c_str());
715  if (!stream)
716  return 0;
717  else
718  return write_to_text_file(stream,set,delimiter);
719  }
720 
721  template <typename T,
722  typename Comparator,
723  typename Allocator>
724  inline std::size_t write_to_text_file(const std::string& file_name,
725  const std::multiset<T,Comparator,Allocator>& multiset,
726  const std::string& delimiter = "")
727  {
728  std::ofstream stream(file_name.c_str());
729  if (!stream)
730  return 0;
731  else
732  return write_to_text_file(stream,multiset,delimiter);
733  }
734 
735  template <typename InputIterator, typename OutputIterator>
736  inline void copy_n(InputIterator itr, std::size_t n, OutputIterator out)
737  {
738  while (n)
739  {
740  (*out) = (*itr);
741  ++itr;
742  ++out;
743  --n;
744  }
745  }
746 
747  template <typename Predicate,
748  typename InputIterator,
749  typename OutputIterator>
750  inline void copy_if(Predicate predicate,
751  const InputIterator begin, const InputIterator end,
752  OutputIterator out)
753  {
754  InputIterator itr = begin;
755  while (end != itr)
756  {
757  if (predicate(*itr))
758  {
759  *(out++) = (*itr);
760  }
761  ++itr;
762  }
763  }
764 
765  template <typename Predicate,
766  typename InputIterator,
767  typename OutputIterator>
768  inline InputIterator copy_while(Predicate predicate,
769  const InputIterator begin, const InputIterator end,
770  OutputIterator out)
771  {
772  InputIterator itr = begin;
773  while (end != itr)
774  {
775  if (!predicate(*itr))
776  return itr;
777  *(out++) = *(itr++);
778  }
779  return end;
780  }
781 
782  template <typename Predicate,
783  typename InputIterator,
784  typename OutputIterator>
785  inline InputIterator copy_until(Predicate predicate,
786  const InputIterator begin, const InputIterator end,
787  OutputIterator out)
788  {
789  InputIterator itr = begin;
790  while (end != itr)
791  {
792  if (predicate(*itr))
793  return itr;
794  *(out++) = *(itr++);
795  }
796  return end;
797  }
798 
799  template <typename InputIterator, typename OutputIterator>
800  inline void extract_unique(const InputIterator begin, const InputIterator end,
801  OutputIterator out)
802  {
803  typedef typename std::iterator_traits<InputIterator>::value_type T;
804  std::vector<T> buffer(begin,end);
805  std::sort(buffer.begin(),buffer.end());
806  std::unique_copy(buffer.begin(),buffer.end(),out);
807  }
808 
809  template <typename Predicate, typename InputIterator>
810  inline bool range_only_contains(Predicate predicate,
811  const InputIterator begin,
812  const InputIterator end)
813  {
814  InputIterator itr = begin;
815  while (end != itr)
816  {
817  if (!predicate(*itr))
818  {
819  return false;
820  }
821  ++itr;
822  }
823  return true;
824  }
825 
826  namespace range
827  {
828  template <typename T>
829  class adapter
830  {
831  public:
832 
833  typedef T value_type;
834  typedef T* iterator;
835  typedef const iterator const_iterator;
836 
837  adapter(T* const begin, T* const end)
838  : begin_(begin),
839  end_(end)
840  {}
841 
842  adapter(const std::pair<T*,T*>& r)
843  : begin_(r.first),
844  end_(r.second)
845  {}
846 
847  adapter(T* const begin, const std::size_t length)
848  : begin_(begin),
849  end_(begin_ + length)
850  {}
851 
852  inline iterator begin() const
853  {
854  return begin_;
855  }
856 
857  inline iterator end() const
858  {
859  return end_;
860  }
861 
862  inline std::size_t size() const
863  {
864  return std::distance(begin_,end_);
865  }
866 
867  inline operator std::string() const
868  {
869  return stringify(begin_,end_);
870  }
871 
872  inline const T& operator[](const std::size_t& index) const
873  {
874  return *(begin_ + index);
875  }
876 
877  inline T& operator[](const std::size_t& index)
878  {
879  return *(begin_ + index);
880  }
881 
882  private:
883 
884  template <typename Type>
885  static inline std::string stringify(Type*,Type*)
886  {
887  static std::string result = "";
888  return result;
889  }
890 
891  static inline std::string stringify(const char* begin, const char* end)
892  {
893  return std::string(begin,end);
894  }
895 
896  iterator begin_;
897  iterator end_;
898  };
899 
902 
903  template <typename T>
904  inline adapter<T> type(const T* begin, const T* end)
905  {
906  return adapter<T>(begin,end);
907  }
908 
909  template <typename T, std::size_t N>
910  inline adapter<T> type(const T (&t)[N])
911  {
912  return adapter<T>(t,N);
913  }
914 
915  static inline adapter<const char> type(const std::string& s)
916  {
917  return adapter<const char>(s.data(),s.size());
918  }
919 
920  template <typename T,
921  typename Allocator,
922  template <typename,typename> class Sequence>
923  inline adapter<typename Sequence<T,Allocator>::iterator> type(const Sequence<T,Allocator>& seq)
924  {
925  return adapter<typename Sequence<T,Allocator>::iterator>(seq.begin(),seq.end());
926  }
927 
929  {
930  return std::string(a.begin(),a.end());
931  }
932 
934  {
935  return std::string(a.begin(),a.end());
936  }
937 
938  } // namespace range
939 
940  template <typename T>
942  {
943  public:
944 
945  typedef T value_type;
946 
948  : delimiter_(d)
949  {}
950 
951  inline bool operator()(const T& d) const
952  {
953  return delimiter_ == d;
954  }
955 
956  private:
957 
959  const T delimiter_;
960  };
961 
962  template <typename T>
964  {
965  public:
966 
967  typedef T value_type;
968 
969  multiple_delimiter_predicate(const T* d_begin, const T* d_end)
970  : length_(std::distance(d_begin,d_end)),
971  delimiter_((length_ <= sbo_buffer_size) ? sbo_buffer : new T[length_]),
972  delimiter_end_(delimiter_ + length_)
973  {
974  std::copy(d_begin,d_end, delimiter_);
975  }
976 
977  multiple_delimiter_predicate(const T d[], const std::size_t& length)
978  : length_(length),
979  delimiter_((length_ <= sbo_buffer_size) ? sbo_buffer : new T[length_]),
980  delimiter_end_(delimiter_ + length_)
981  {
982  std::copy(d,d + length, delimiter_);
983  }
984 
985  template <typename Iterator>
986  multiple_delimiter_predicate(const Iterator begin, const Iterator end)
987  : length_(std::distance(begin,end)),
988  delimiter_((length_ <= sbo_buffer_size) ? sbo_buffer : new T[length_]),
989  delimiter_end_(delimiter_ + length_)
990  {
991  //static_assert(T == std::iterator_traits<Iterator>::value_type);
992  std::copy(begin,end, delimiter_);
993  }
994 
995  template <typename Type>
997  : length_(std::distance(r.begin(),r.end())),
998  delimiter_((length_ <= sbo_buffer_size) ? sbo_buffer : new T[length_]),
999  delimiter_end_(delimiter_ + length_)
1000  {
1001  //static_assert(T == std::iterator_traits<Iterator>::value_type);
1002  std::copy(r.begin(),r.end(), delimiter_);
1003  }
1004 
1006  {
1007  if (length_ > sbo_buffer_size)
1008  {
1009  delete[] delimiter_;
1010  }
1011  }
1012 
1013  inline bool operator()(const T& d) const
1014  {
1015  return (std::find(delimiter_,delimiter_end_,d) != delimiter_end_);
1016  }
1017 
1018  private:
1019 
1022 
1023  std::size_t length_;
1024  T* delimiter_;
1025  T* delimiter_end_;
1026  enum { sbo_buffer_size = 32 };
1027  T sbo_buffer[sbo_buffer_size];
1028  };
1029 
1031  {
1032  public:
1033 
1034  template <typename Iterator>
1035  multiple_char_delimiter_predicate(const Iterator begin, const Iterator end)
1036  {
1037  setup_delimiter_table(begin,end);
1038  }
1039 
1041  {
1042  setup_delimiter_table(s.data(),s.data() + s.size());
1043  }
1044 
1045  inline bool operator()(const unsigned char& c) const
1046  {
1047  return (delimiter_table_[c]);
1048  }
1049 
1050  inline bool operator()(const char& c) const
1051  {
1052  return operator()(static_cast<unsigned char>(c));
1053  }
1054 
1055  private:
1056 
1057  static const std::size_t table_size = 256;
1058 
1059  template <typename Iterator>
1060  inline void setup_delimiter_table(const Iterator begin, const Iterator end)
1061  {
1062  std::fill_n(delimiter_table_,table_size,false);
1063  for (Iterator itr = begin; itr != end; ++itr)
1064  {
1065  delimiter_table_[static_cast<unsigned char>(*itr)] = true;
1066  }
1067  }
1068 
1069  bool delimiter_table_[table_size];
1070  };
1071 
1072  namespace details
1073  {
1074  template <typename Allocator,
1075  template <typename,typename> class Sequence>
1077  {
1078  typedef Sequence<std::size_t,Allocator> sequence_t;
1080  : itr_(sequence.begin()),
1081  end_(sequence.end()),
1082  current_index_(0),
1083  check_(true)
1084  {}
1085 
1086  template <typename T>
1087  inline bool operator()(const T&)
1088  {
1089  if (check_)
1090  {
1091  if (current_index_++ == *itr_)
1092  {
1093  if (end_ == ++itr_)
1094  {
1095  check_ = false;
1096  }
1097  return true;
1098  }
1099  }
1100  return false;
1101  }
1102 
1103  typename sequence_t::const_iterator itr_;
1104  typename sequence_t::const_iterator end_;
1105  std::size_t current_index_;
1106  bool check_;
1107  };
1108  }
1109 
1110  template <typename Allocator,
1111  template <typename,typename> class Sequence>
1112  inline details::index_remover_impl<Allocator,Sequence> index_remover(const Sequence<std::size_t,Allocator>& sequence)
1113  {
1115  }
1116 
1117  template <typename Iterator, typename Predicate>
1118  inline std::size_t remove_inplace(Predicate predicate,
1119  Iterator begin,
1120  Iterator end)
1121  {
1122  Iterator itr1 = begin;
1123  Iterator itr2 = begin;
1124  std::size_t removal_count = 0;
1125  while (end != itr1)
1126  {
1127  if (predicate(*itr1))
1128  {
1129  ++itr1;
1130  ++removal_count;
1131  }
1132  else
1133  {
1134  if (itr1 != itr2)
1135  {
1136  (*itr2) = (*itr1);
1137  }
1138  ++itr1;
1139  ++itr2;
1140  }
1141  }
1142  return removal_count;
1143  }
1144 
1145  template <typename T, typename Predicate>
1146  inline std::size_t remove_inplace(Predicate predicate, const range::adapter<T>& r)
1147  {
1148  return remove_inplace(predicate,r.begin(),r.end());
1149  }
1150 
1151  template <typename Predicate,
1152  typename T,
1153  typename Allocator,
1154  template <typename,typename> class Sequence>
1155  inline std::size_t remove_inplace(Predicate predicate, Sequence<T,Allocator>& sequence)
1156  {
1157  const std::size_t removal_count = remove_inplace(predicate,sequence.begin(),sequence.end());
1158  sequence.resize(sequence.size() - removal_count);
1159  return removal_count;
1160  }
1161 
1162  inline void remove_inplace(const std::string::value_type c, std::string& s)
1163  {
1164  const std::size_t removal_count = remove_inplace(single_delimiter_predicate<std::string::value_type>(c),
1165  const_cast<char*>(s.data()),
1166  const_cast<char*>(s.data() + s.size()));
1167  if (removal_count > 0)
1168  {
1169  s.resize(s.size() - removal_count);
1170  }
1171  }
1172 
1173  template <typename Predicate>
1174  inline void remove_inplace(Predicate predicate, std::string& s)
1175  {
1176  const std::size_t removal_count = remove_inplace(predicate,
1177  const_cast<char*>(s.data()),
1178  const_cast<char*>(s.data() + s.size()));
1179  if (removal_count > 0)
1180  {
1181  s.resize(s.size() - removal_count);
1182  }
1183  }
1184 
1185  template <typename Iterator, typename Predicate>
1186  inline std::size_t remove_consecutives_inplace(Predicate predicate,
1187  Iterator begin,
1188  Iterator end)
1189  {
1190  if (0 == std::distance(begin,end)) return 0;
1191  Iterator itr1 = begin;
1192  Iterator itr2 = begin;
1193  typename std::iterator_traits<Iterator>::value_type prev = *begin;
1194  std::size_t removal_count = 0;
1195  ++itr1;
1196  ++itr2;
1197  while (end != itr1)
1198  {
1199  while ((end != itr1) && (!predicate(*itr1) || !predicate(prev)))
1200  {
1201  if (itr1 != itr2)
1202  {
1203  (*itr2) = (*itr1);
1204  }
1205  prev = (*itr1);
1206  ++itr1;
1207  ++itr2;
1208  }
1209 
1210  while ((end != itr1) && predicate(*itr1))
1211  {
1212  ++itr1;
1213  ++removal_count;
1214  }
1215  }
1216 
1217  return removal_count;
1218  }
1219 
1220  template <typename T, typename Predicate>
1221  inline std::size_t remove_consecutives_inplace(Predicate predicate, const range::adapter<T>& r)
1222  {
1223  return remove_consecutives_inplace(predicate,r.begin(),r.end());
1224  }
1225 
1226  inline void remove_consecutives_inplace(const std::string::value_type c, std::string& s)
1227  {
1228  if (s.empty()) return;
1230  const_cast<char*>(s.data()),
1231  const_cast<char*>(s.data() + s.size()));
1232  if (removal_count > 0)
1233  {
1234  s.resize(s.size() - removal_count);
1235  }
1236  }
1237 
1238  inline void remove_consecutives_inplace(const std::string& rem_chars, std::string& s)
1239  {
1240  if (s.empty()) return;
1241  const std::size_t removal_count = remove_consecutives_inplace(multiple_char_delimiter_predicate(rem_chars),
1242  const_cast<char*>(s.data()),
1243  const_cast<char*>(s.data() + s.size()));
1244  if (removal_count > 0)
1245  {
1246  s.resize(s.size() - removal_count);
1247  }
1248  }
1249 
1250  namespace details
1251  {
1252  #if (defined(__MINGW32_VERSION)) ||\
1253  (defined(__APPLE__) && (__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1070)) ||\
1254  (defined(_WIN32) && (_MSC_VER < 1400))
1255  inline std::size_t strnlength(const char* s, const std::size_t& n)
1256  {
1257  const char *end = reinterpret_cast<const char*>(memchr(s, '\0', n));
1258  return end ? (size_t) (end - s) : n;
1259  }
1260  #else
1261  inline std::size_t strnlength(const char* s, const std::size_t& n)
1262  {
1263  return strnlen(s,n);
1264  }
1265  #endif
1266  }
1267 
1268  inline void remove_consecutives_inplace(const char* rem_chars, std::string& s)
1269  {
1270  if (s.empty()) return;
1271  const std::size_t removal_count = remove_consecutives_inplace(multiple_char_delimiter_predicate(
1272  rem_chars,
1273  rem_chars + details::strnlength(rem_chars,256)),
1274  const_cast<char*>(s.data()),
1275  const_cast<char*>(s.data() + s.size()));
1276  if (removal_count > 0)
1277  {
1278  s.resize(s.size() - removal_count);
1279  }
1280  }
1281 
1282  template <typename Predicate>
1283  inline void remove_consecutives_inplace(Predicate predicate, std::string& s)
1284  {
1285  if (s.empty()) return;
1286  const std::size_t removal_count = remove_consecutives_inplace(predicate,
1287  const_cast<char*>(s.data()),
1288  const_cast<char*>(s.data() + s.size()));
1289  if (removal_count > 0)
1290  {
1291  s.resize(s.size() - removal_count);
1292  }
1293  }
1294 
1295  template <typename Iterator>
1296  inline std::size_t remove_consecutives_inplace(Iterator begin, Iterator end)
1297  {
1298  if (0 == std::distance(begin,end)) return 0;
1299 
1300  Iterator itr1 = begin; ++itr1;
1301  Iterator itr2 = begin; ++itr2;
1302  typename std::iterator_traits<Iterator>::value_type prev = *begin;
1303  std::size_t removal_count = 0;
1304 
1305  while (end != itr1)
1306  {
1307  while ((end != itr1) && (prev != (*itr1)))
1308  {
1309  if (itr1 != itr2)
1310  {
1311  (*itr2) = (*itr1);
1312  }
1313  prev = (*itr1);
1314  ++itr1;
1315  ++itr2;
1316  }
1317 
1318  while ((end != itr1) && (prev == (*itr1)))
1319  {
1320  ++itr1;
1321  ++removal_count;
1322  }
1323  }
1324 
1325  return removal_count;
1326  }
1327 
1328  template <typename T>
1329  inline std::size_t remove_consecutives_inplace(const range::adapter<T>& r)
1330  {
1331  return remove_consecutives_inplace(r.begin(),r.end());
1332  }
1333 
1334  template <typename T,
1335  typename Allocator,
1336  template <typename,typename> class Sequence>
1337  inline void remove_consecutives_inplace(Sequence<T,Allocator>& sequence)
1338  {
1339  const std::size_t removal_count = remove_consecutives_inplace(sequence.begin(),sequence.end());
1340  sequence.resize(sequence.size() - removal_count);
1341  }
1342 
1344  {
1345  std::size_t removal_count = remove_consecutives_inplace(const_cast<char*>(s.data()),
1346  const_cast<char*>(s.data() + s.size()));
1347 
1348  if (removal_count > 0)
1349  {
1350  s.resize(s.size() - removal_count);
1351  }
1352  }
1353 
1355  {
1356  std::string::value_type table[0xFF];
1357  std::fill_n(table,0xFF,static_cast<char>(0));
1358  std::string result;
1359  result.reserve(str.size());
1360  for (std::size_t i = 0; i < str.size(); ++i)
1361  {
1362  const char c = str[i];
1363  if (0 == table[static_cast<std::size_t>(c)])
1364  {
1365  table[static_cast<std::size_t>(c)] = 0x01;
1366  result += c;
1367  }
1368  }
1369  return result;
1370  }
1371 
1373  {
1374  return remove_duplicates(str);
1375  }
1376 
1377  template <typename Iterator, typename Predicate>
1378  inline std::size_t remove_trailing(Predicate predicate,
1379  Iterator begin,
1380  Iterator end)
1381  {
1382  const std::size_t length = std::distance(begin,end);
1383  if (0 == length)
1384  return 0;
1385  Iterator itr = begin + (length - 1);
1386  std::size_t removal_count = 0;
1387 
1388  while ((begin != itr) && predicate(*itr))
1389  {
1390  --itr;
1391  ++removal_count;
1392  }
1393 
1394  return removal_count;
1395  }
1396 
1397  template <typename T, typename Predicate>
1398  inline std::size_t remove_trailing(Predicate predicate, const range::adapter<T>& r)
1399  {
1400  return remove_trailing(predicate,r.begin(),r.end());
1401  }
1402 
1403  inline void remove_trailing(const std::string::value_type c, std::string& s)
1404  {
1405  if (s.empty()) return;
1406  const std::size_t removal_count = remove_trailing(single_delimiter_predicate<std::string::value_type>(c),
1407  const_cast<char*>(s.data()),
1408  const_cast<char*>(s.data() + s.size()));
1409  if (removal_count > 0)
1410  {
1411  s.resize(s.size() - removal_count);
1412  }
1413  }
1414 
1415  inline void remove_trailing(const std::string& rem_chars, std::string& s)
1416  {
1417  if (s.empty()) return;
1418  const std::size_t removal_count = remove_trailing(multiple_char_delimiter_predicate(rem_chars),
1419  const_cast<char*>(s.data()),
1420  const_cast<char*>(s.data() + s.size()));
1421  if (removal_count > 0)
1422  {
1423  s.resize(s.size() - removal_count);
1424  }
1425  }
1426 
1427  inline void remove_trailing(const char* rem_chars, std::string& s)
1428  {
1429  const std::size_t removal_count = remove_trailing(multiple_char_delimiter_predicate(
1430  rem_chars,
1431  rem_chars + details::strnlength(rem_chars,256)),
1432  const_cast<char*>(s.data()),
1433  const_cast<char*>(s.data() + s.size()));
1434  if (removal_count > 0)
1435  {
1436  s.resize(s.size() - removal_count);
1437  }
1438  }
1439 
1440  template <typename Predicate>
1441  inline void remove_trailing(Predicate predicate, std::string& s)
1442  {
1443  if (s.empty()) return;
1444  const std::size_t removal_count = remove_trailing(predicate,
1445  const_cast<char*>(s.data()),
1446  const_cast<char*>(s.data() + s.size()));
1447  if (removal_count > 0)
1448  {
1449  s.resize(s.size() - removal_count);
1450  }
1451  }
1452 
1453  template <typename Iterator, typename Predicate>
1454  inline std::size_t remove_leading(Predicate predicate,
1455  Iterator begin,
1456  Iterator end)
1457  {
1458  const std::size_t length = std::distance(begin,end);
1459  if (0 == length)
1460  return 0;
1461  Iterator itr = begin;
1462  std::size_t removal_count = 0;
1463 
1464  while ((end != itr) && predicate(*itr))
1465  {
1466  ++itr;
1467  ++removal_count;
1468  }
1469 
1470  std::copy(itr,end,begin);
1471  return removal_count;
1472  }
1473 
1474  template <typename T, typename Predicate>
1475  inline std::size_t remove_leading(Predicate predicate, const range::adapter<T>& r)
1476  {
1477  return remove_leading(predicate,r.begin(),r.end());
1478  }
1479 
1480  inline void remove_leading(const std::string::value_type c, std::string& s)
1481  {
1482  if (s.empty()) return;
1483  const std::size_t removal_count = remove_leading(single_delimiter_predicate<std::string::value_type>(c),
1484  const_cast<char*>(s.data()),
1485  const_cast<char*>(s.data() + s.size()));
1486  if (removal_count > 0)
1487  {
1488  s.resize(s.size() - removal_count);
1489  }
1490  }
1491 
1492  inline void remove_leading(const std::string& rem_chars, std::string& s)
1493  {
1494  if (s.empty()) return;
1495  const std::size_t removal_count = remove_leading(multiple_char_delimiter_predicate(rem_chars),
1496  const_cast<char*>(s.data()),
1497  const_cast<char*>(s.data() + s.size()));
1498  if (removal_count > 0)
1499  {
1500  s.resize(s.size() - removal_count);
1501  }
1502  }
1503 
1504  inline void remove_leading(const char* rem_chars, std::string& s)
1505  {
1506  if (s.empty()) return;
1507  const std::size_t removal_count = remove_leading(multiple_char_delimiter_predicate(
1508  rem_chars,
1509  rem_chars + details::strnlength(rem_chars,256)),
1510  const_cast<char*>(s.data()),
1511  const_cast<char*>(s.data() + s.size()));
1512  if (removal_count > 0)
1513  {
1514  s.resize(s.size() - removal_count);
1515  }
1516  }
1517 
1518  inline void remove_leading_trailing(const std::string& rem_chars, std::string& s)
1519  {
1520  remove_leading(rem_chars,s);
1521  remove_trailing(rem_chars,s);
1522  }
1523 
1524  template <typename Predicate>
1525  inline void remove_leading(Predicate predicate, std::string& s)
1526  {
1527  if (s.empty()) return;
1528  const std::size_t removal_count = remove_leading(predicate,
1529  const_cast<char*>(s.data()),
1530  const_cast<char*>(s.data() + s.size()));
1531  if (removal_count > 0)
1532  {
1533  s.resize(s.size() - removal_count);
1534  }
1535  }
1536 
1537  template <typename Allocator,
1538  template <typename,typename> class Sequence>
1539  void remove_empty_strings(Sequence<std::string,Allocator>& seq)
1540  {
1541  struct is_empty { static inline bool check(const std::string& s) { return s.empty(); } };
1542  seq.erase(std::remove_if(seq.begin(),seq.end(),is_empty::check),seq.end());
1543  }
1544 
1545  template <typename Allocator>
1546  void remove_empty_strings(std::list<std::string,Allocator>& l)
1547  {
1548  struct is_empty { static inline bool check(const std::string& s) { return s.empty(); } };
1549  l.remove_if(is_empty::check);
1550  }
1551 
1552  template <typename Comparator, typename Allocator>
1553  void remove_empty_strings(std::set<std::string,Comparator,Allocator>& set)
1554  {
1555  struct is_empty { static inline bool check(const std::string& s) { return s.empty(); } };
1556  typename std::set<std::string,Comparator,Allocator>::iterator itr = set.begin();
1557  while (set.end() != itr)
1558  {
1559  if ((*itr).empty())
1560  set.erase(itr++);
1561  else
1562  ++itr;
1563  }
1564  }
1565 
1566  template <typename Comparator, typename Allocator>
1567  void remove_empty_strings(std::multiset<std::string,Comparator,Allocator>& set)
1568  {
1569  struct is_empty { static inline bool check(const std::string& s) { return s.empty(); } };
1570  typename std::multiset<std::string,Comparator,Allocator>::iterator itr = set.begin();
1571  while (set.end() != itr)
1572  {
1573  if ((*itr).empty())
1574  set.erase(itr++);
1575  else
1576  ++itr;
1577  }
1578  }
1579 
1580  template <typename Iterator>
1581  inline void replace(const typename std::iterator_traits<Iterator>::value_type& c1,
1582  const typename std::iterator_traits<Iterator>::value_type& c2,
1583  const Iterator begin,
1584  const Iterator end)
1585  {
1586  for (Iterator itr = begin; end != itr; ++itr)
1587  {
1588  if (c1 == (*itr))
1589  {
1590  (*itr) = c2;
1591  }
1592  }
1593  }
1594 
1595  inline void replace(const std::string::value_type& c0,
1596  const std::string::value_type& c1,
1597  std::string& s)
1598  {
1599  replace(c0,c1,const_cast<char*>(s.data()),const_cast<char*>(s.data() + s.size()));
1600  }
1601 
1602  template <typename T>
1603  inline void replace(const T& c1, const T& c2, const range::adapter<T>& r)
1604  {
1605  replace(c1,c2,r.begin(),r.end());
1606  }
1607 
1608  inline void replace_pattern(const std::string& s, // input
1609  const std::string& p, // pattern
1610  const std::string& r, // replacement
1611  std::string& n)
1612  {
1613  if (p.empty() || (p == r))
1614  {
1615  n.assign(s);
1616  return;
1617  }
1618 
1619  const std::size_t p_size = p.size();
1620  const std::size_t r_size = r.size();
1621  int inc = static_cast<int>(r_size) - static_cast<int>(p_size);
1622  std::size_t pos = 0;
1623  std::vector<std::size_t> delta_list;
1624  delta_list.reserve(std::min<std::size_t>(32,(s.size() / p_size) + 1));
1625 
1626  while (std::string::npos != (pos = s.find(p,pos)))
1627  {
1628  delta_list.push_back(pos);
1629  pos += p_size;
1630  }
1631 
1632  if (delta_list.empty())
1633  {
1634  n.assign(s);
1635  return;
1636  }
1637 
1638  n.resize(delta_list.size() * inc + s.size(), 0x00);
1639  char* n_itr = const_cast<char*>(n.data());
1640  const char* s_end = s.data() + s.size();
1641  const char* s_itr = s.data();
1642  const char* r_begin = r.data();
1643  const char* r_end = r.data() + r_size;
1644  const std::size_t delta_list_size = delta_list.size();
1645  std::size_t i = 0;
1646  std::size_t delta = delta_list[0];
1647 
1648  for ( ; ; )
1649  {
1650  std::copy(s_itr, s_itr + delta, n_itr);
1651  s_itr += p_size + delta;
1652  n_itr += delta;
1653  std::copy(r_begin, r_end, n_itr);
1654  n_itr += r_size;
1655  if (++i >= delta_list_size)
1656  break;
1657  delta = delta_list[i] - (delta_list[i - 1] + p_size);
1658  }
1659 
1660  if (s_end != s_itr)
1661  {
1662  std::copy(s_itr, s_end, n_itr);
1663  }
1664  }
1665 
1666  template <typename InputIterator, typename OutputIterator>
1667  inline std::size_t replace_pattern(const InputIterator s_begin, const InputIterator s_end, // input
1668  const InputIterator p_begin, const InputIterator p_end, // pattern
1669  const InputIterator r_begin, const InputIterator r_end, // replacement
1670  OutputIterator out)
1671  {
1672  typedef typename std::iterator_traits<InputIterator>::value_type T;
1673 
1674  InputIterator s_itr = s_begin;
1675  InputIterator r_itr = r_begin;
1676  InputIterator p_itr = p_begin;
1677 
1678  const std::size_t p_size = std::distance(p_begin,p_end);
1679  const std::size_t r_size = std::distance(r_begin,r_end);
1680 
1681  if ((0 == p_size) || ((p_size == r_size) && std::equal(p_begin,p_end,r_begin)))
1682  {
1683  std::copy(s_begin,s_end,out);
1684  return std::distance(s_begin,s_end);
1685  }
1686 
1687  std::size_t pos = 0;
1688  std::size_t prev_pos = 0;
1689  std::size_t count = 0;
1690  std::size_t new_size = std::distance(s_begin,s_end);
1691  int inc = r_size - p_size;
1692 
1693  InputIterator temp_s_itr = s_itr;
1694 
1695  while (s_end != s_itr)
1696  {
1697  /*
1698  Need to replace the following search code with
1699  Knuth-Pratt-Morris or Boyer-Moore string search
1700  algorithms.
1701  */
1702  bool found = true;
1703  p_itr = p_begin;
1704  temp_s_itr = s_itr;
1705 
1706  while ((p_end != p_itr) && (s_end != temp_s_itr))
1707  {
1708  if (*(temp_s_itr++) != *(p_itr++))
1709  {
1710  found = false;
1711  break;
1712  }
1713  }
1714 
1715  if (found && (p_itr == p_end))
1716  {
1717  ++count;
1718  new_size += inc;
1719  s_itr = temp_s_itr;
1720  }
1721  else
1722  ++s_itr;
1723  }
1724 
1725  s_itr = s_begin;
1726  p_itr = p_begin;
1727 
1728  pos = 0;
1729  prev_pos = 0;
1730 
1731  temp_s_itr = s_itr;
1732 
1733  while (0 < count)
1734  {
1735  p_itr = p_begin;
1736  bool found = true;
1737  InputIterator pattern_start = temp_s_itr;
1738 
1739  while ((p_end != p_itr) && (s_end != temp_s_itr))
1740  {
1741  if (*(temp_s_itr++) != *(p_itr++))
1742  {
1743  found = false;
1744  temp_s_itr = pattern_start;
1745  ++temp_s_itr;
1746  break;
1747  }
1748  }
1749 
1750  if (!found || (p_itr != p_end)) continue;
1751 
1752  pos = std::distance(s_begin,temp_s_itr) - p_size;
1753  int diff = pos - prev_pos;
1754 
1755  std::copy(s_itr,s_itr + diff, out);
1756  s_itr = temp_s_itr;
1757  std::copy(r_itr,r_end, out);
1758 
1759  pos += p_size;
1760  prev_pos = pos;
1761  --count;
1762  }
1763 
1764  std::copy(s_itr,s_end,out);
1765 
1766  return new_size;
1767  }
1768 
1769  inline void remove_pattern(const std::string& s,
1770  const std::string& p,
1771  std::string& n)
1772  {
1773  static const std::string r("");
1774  replace_pattern(s,p,r,n);
1775  }
1776 
1777  inline void sort(std::string& s)
1778  {
1779  std::sort(s.begin(),s.end());
1780  }
1781 
1782  template <typename Iterator>
1783  inline bool match(const Iterator pattern_begin,
1784  const Iterator pattern_end,
1785  const Iterator data_begin,
1786  const Iterator data_end,
1787  const typename std::iterator_traits<Iterator>::value_type& zero_or_more,
1788  const typename std::iterator_traits<Iterator>::value_type& zero_or_one)
1789  {
1790  /*
1791  Credits: Adapted from code by Jack Handy (2001)
1792  */
1793  if (0 == std::distance(data_begin,data_end)) return false;
1794 
1795  Iterator d_itr = data_begin;
1796  Iterator p_itr = pattern_begin;
1797  Iterator c_itr = data_begin;
1798  Iterator m_itr = data_begin;
1799 
1800  while ((data_end != d_itr) && (zero_or_more != (*p_itr)))
1801  {
1802  if (((*p_itr) != (*d_itr)) && (zero_or_one != (*p_itr)))
1803  {
1804  return false;
1805  }
1806  ++p_itr;
1807  ++d_itr;
1808  }
1809 
1810  while (data_end != d_itr)
1811  {
1812  if (zero_or_more == (*p_itr))
1813  {
1814  if (pattern_end == (++p_itr))
1815  {
1816  return true;
1817  }
1818  m_itr = p_itr;
1819  c_itr = d_itr;
1820  ++c_itr;
1821  }
1822  else if (((*p_itr) == (*d_itr)) || (zero_or_one == (*p_itr)))
1823  {
1824  ++p_itr;
1825  ++d_itr;
1826  }
1827  else
1828  {
1829  p_itr = m_itr;
1830  d_itr = c_itr++;
1831  }
1832  }
1833 
1834  while ((p_itr != pattern_end) && (zero_or_more == (*p_itr))) ++p_itr;
1835 
1836  return (p_itr == pattern_end);
1837  }
1838 
1839  inline bool match(const std::string& wild_card,
1840  const std::string& str)
1841  {
1842  /*
1843  * : Zero or more match
1844  ? : Zero or one match
1845  */
1846  return match(wild_card.data(),
1847  wild_card.data() + wild_card.size(),
1848  str.data(),
1849  str.data() + str.size(),
1850  '*',
1851  '?');
1852  }
1853 
1854  inline bool imatch_char(const char c1, const char c2)
1855  {
1856  return std::toupper(c1) == std::toupper(c2);
1857  }
1858 
1859  template <typename InputIterator>
1860  inline bool imatch(const InputIterator begin1, const InputIterator end1,
1861  const InputIterator begin2, const InputIterator end2)
1862  {
1863  typedef typename details::is_valid_iterator<InputIterator>::type itr_type;
1864  if (std::distance(begin1,end1) != std::distance(begin2,end2))
1865  {
1866  return false;
1867  }
1868 
1869  InputIterator itr1 = begin1;
1870  InputIterator itr2 = begin2;
1871 
1872  while (end1 != itr1)
1873  {
1874  //if (std::toupper(*itr1, std::locale::classic()) != std::toupper(*it2, std::locale::classic()))
1875  if (std::toupper(*itr1) != std::toupper(*itr2))
1876  {
1877  return false;
1878  }
1879  ++itr1;
1880  ++itr2;
1881  }
1882 
1883  return true;
1884  }
1885 
1886  template <typename T>
1887  inline bool imatch(const range::adapter<T>& r1, const range::adapter<T>& r2)
1888  {
1889  return imatch(r1.begin(),r1.end(),r2.begin(),r2.end());
1890  }
1891 
1892  inline bool imatch(const std::string& s1, const std::string& s2)
1893  {
1894  return imatch(s1.data(),
1895  s1.data() + s1.size(),
1896  s2.data(),
1897  s2.data() + s2.size());
1898  }
1899 
1900  template <typename Iterator>
1901  inline Iterator imatch(const std::string& s, const Iterator begin, const Iterator end)
1902  {
1903  for (const std::string* itr = begin; end != itr; ++itr)
1904  {
1905  if (imatch(s,*itr))
1906  {
1907  return itr;
1908  }
1909  }
1910  return end;
1911  }
1912 
1913  template <typename Allocator,
1914  template <typename,typename> class Sequence>
1915  inline bool imatch(const std::string& s, const Sequence<std::string,Allocator>& sequence)
1916  {
1917  return (sequence.end() != imatch(s,sequence.begin(),sequence.end()));
1918  }
1919 
1920  template <typename Comparator, typename Allocator>
1921  inline bool imatch(const std::string& s, const std::set<std::string,Comparator,Allocator>& set)
1922  {
1923  return imatch(s,set.begin(),set.end());
1924  }
1925 
1926  template <typename Comparator, typename Allocator>
1927  inline bool imatch(const std::string& s, const std::multiset<std::string,Comparator,Allocator>& multiset)
1928  {
1929  return imatch(s,multiset.begin(),multiset.end());
1930  }
1931 
1932  template <typename Iterator, typename OutputIterator>
1933  inline std::size_t find_all(const Iterator pattern_begin,
1934  const Iterator pattern_end,
1935  const Iterator begin,
1936  const Iterator end,
1937  OutputIterator out)
1938  {
1939  Iterator itr = begin;
1940  const std::size_t pattern_length = std::distance(pattern_begin,pattern_end);
1941  std::size_t match_count = 0;
1942  while (end != (itr = std::search(itr, end, pattern_begin, pattern_end)))
1943  {
1944  (*out) = std::make_pair(itr,itr + pattern_length);
1945  itr += pattern_length;
1946  ++out;
1947  ++match_count;
1948  }
1949  return match_count;
1950  }
1951 
1952  template <typename Iterator,
1953  typename Range,
1954  typename Allocator,
1955  template <typename,typename> class Sequence>
1956  inline std::size_t find_all(const Iterator pattern_begin,
1957  const Iterator pattern_end,
1958  const Iterator begin,
1959  const Iterator end,
1960  Sequence<Range,Allocator>& seq)
1961  {
1962  return find_all(pattern_begin,pattern_end,begin,end,std::back_inserter(seq));
1963  }
1964 
1965  inline std::size_t ifind(const std::string& pattern, const std::string& data)
1966  {
1967  if (pattern.size() > data.size())
1968  return std::string::npos;
1969  const char* result_itr = std::search(data.data(),data.data() + data.size(),
1970  pattern.data(), pattern.data() + pattern.size(),
1971  imatch_char);
1972  if ((data.data() + data.size()) == result_itr)
1973  return std::string::npos;
1974  else
1975  return std::distance(data.data(),result_itr);
1976  }
1977 
1978  template <typename Iterator, typename OutputIterator>
1979  inline std::size_t ifind_all(const Iterator pattern_begin,
1980  const Iterator pattern_end,
1981  const Iterator begin,
1982  const Iterator end,
1983  OutputIterator out)
1984  {
1985  Iterator itr = begin;
1986  const std::size_t pattern_length = std::distance(pattern_begin,pattern_end);
1987  std::size_t match_count = 0;
1988 
1989  while (end != (itr = std::search(itr, end, pattern_begin, pattern_end, imatch_char)))
1990  {
1991  (*out) = std::make_pair(itr,itr + pattern_length);
1992  itr += pattern_length;
1993  ++out;
1994  ++match_count;
1995  }
1996 
1997  return match_count;
1998  }
1999 
2000  template <typename OutputIterator>
2001  inline std::size_t find_all(const std::string& pattern,
2002  const std::string& data,
2003  OutputIterator out)
2004  {
2005  return find_all(pattern.data(), pattern.data() + pattern.size(),
2006  data.data(), data.data() + data.size(),
2007  out);
2008  }
2009 
2010  template <typename Range,
2011  typename Allocator,
2012  template <typename,typename> class Sequence>
2013  inline std::size_t find_all(const std::string& pattern,
2014  const std::string& data,
2015  Sequence<Range,Allocator>& seq)
2016  {
2017  return find_all(pattern,data,std::back_inserter(seq));
2018  }
2019 
2020  template <typename OutputIterator>
2021  inline std::size_t ifind_all(const std::string& pattern,
2022  const std::string& data,
2023  OutputIterator out)
2024  {
2025  return ifind_all(pattern.data(), pattern.data() + pattern.size(),
2026  data.data(), data.data() + data.size(),
2027  out);
2028  }
2029 
2030  template <typename Range,
2031  typename Allocator,
2032  template <typename,typename> class Sequence>
2033  inline std::size_t ifind_all(const std::string& pattern,
2034  const std::string& data,
2035  Sequence<Range,Allocator>& seq)
2036  {
2037  return ifind_all(pattern,data,std::back_inserter(seq));
2038  }
2039 
2040  template <typename InputIterator>
2041  inline bool begins_with(const InputIterator pattern_begin,
2042  const InputIterator pattern_end,
2043  const InputIterator begin,
2044  const InputIterator end)
2045  {
2046  typedef typename details::is_valid_iterator<InputIterator>::type itr_type;
2047  if (std::distance(pattern_begin,pattern_end) <= std::distance(begin,end))
2048  {
2049  return std::equal(pattern_begin,pattern_end,begin);
2050  }
2051  else
2052  return false;
2053  }
2054 
2055  inline bool begins_with(const std::string& pattern, const std::string& data)
2056  {
2057  if (pattern.size() <= data.size())
2058  {
2059  return begins_with(pattern.data(),
2060  pattern.data() + pattern.size(),
2061  data.data(),
2062  data.data() + data.size());
2063  }
2064  else
2065  return false;
2066  }
2067 
2068  template <typename InputIterator>
2069  inline bool ibegins_with(const InputIterator pattern_begin,
2070  const InputIterator pattern_end,
2071  const InputIterator begin,
2072  const InputIterator end)
2073  {
2074  typedef typename details::is_valid_iterator<InputIterator>::type itr_type;
2075  if (std::distance(pattern_begin,pattern_end) <= std::distance(begin,end))
2076  {
2077  return std::equal(pattern_begin,pattern_end,begin,imatch_char);
2078  }
2079  else
2080  return false;
2081  }
2082 
2083  inline bool ibegins_with(const std::string& pattern, const std::string& data)
2084  {
2085  if (pattern.size() <= data.size())
2086  {
2087  return ibegins_with(pattern.data(),
2088  pattern.data() + pattern.size(),
2089  data.data(),
2090  data.data() + data.size());
2091  }
2092  else
2093  return false;
2094  }
2095 
2096  template <typename InputIterator>
2097  inline bool ends_with(const InputIterator pattern_begin,
2098  const InputIterator pattern_end,
2099  const InputIterator begin,
2100  const InputIterator end)
2101  {
2102  typedef typename details::is_valid_iterator<InputIterator>::type itr_type;
2103  const std::size_t pattern_length = std::distance(pattern_begin,pattern_end);
2104  const std::size_t data_length = std::distance(begin,end);
2105  if (pattern_length <= data_length)
2106  {
2107  return std::equal(pattern_begin,
2108  pattern_end,
2109  begin + (data_length - pattern_length));
2110  }
2111  else
2112  return false;
2113  }
2114 
2115  inline bool ends_with(const std::string& pattern, const std::string& data)
2116  {
2117  if (pattern.size() <= data.size())
2118  {
2119  return ends_with(pattern.data(),
2120  pattern.data() + pattern.size(),
2121  data.data(),
2122  data.data() + data.size());
2123  }
2124  else
2125  return false;
2126  }
2127 
2128  template <typename InputIterator>
2129  inline bool iends_with(const InputIterator pattern_begin,
2130  const InputIterator pattern_end,
2131  const InputIterator begin,
2132  const InputIterator end)
2133  {
2134  typedef typename details::is_valid_iterator<InputIterator>::type itr_type;
2135  const std::size_t pattern_length = std::distance(pattern_begin,pattern_end);
2136  const std::size_t data_length = std::distance(begin,end);
2137  if (pattern_length <= data_length)
2138  {
2139  return std::equal(pattern_begin,
2140  pattern_end,
2141  begin + (data_length - pattern_length),
2142  imatch_char);
2143  }
2144  else
2145  return false;
2146  }
2147 
2148  inline bool iends_with(const std::string& pattern, const std::string& data)
2149  {
2150  if (pattern.size() <= data.size())
2151  {
2152  return iends_with(pattern.data(),
2153  pattern.data() + pattern.size(),
2154  data.data(),
2155  data.data() + data.size());
2156  }
2157  else
2158  return false;
2159  }
2160 
2161  inline std::size_t index_of(const std::string& pattern, const std::string& data)
2162  {
2163  if (pattern.empty())
2164  return std::string::npos;
2165  else if (data.empty())
2166  return std::string::npos;
2167  else if (pattern.size() > data.size())
2168  return std::string::npos;
2169  const char* itr = std::search(data.data(),
2170  data.data() + data.size(),
2171  pattern.data(),
2172  pattern.data() + pattern.size());
2173  return ((data.data() + data.size()) == itr) ? std::string::npos : std::distance(data.data(),itr);
2174  }
2175 
2176  namespace tokenize_options
2177  {
2178  typedef std::size_t type;
2179  enum
2180  {
2185  };
2186 
2187  static inline bool perform_compress_delimiters(const type& split_opt)
2188  {
2189  return compress_delimiters == (split_opt & compress_delimiters);
2190  }
2191 
2192  static inline bool perform_include_1st_delimiter(const type& split_opt)
2193  {
2194  return include_1st_delimiter == (split_opt & include_1st_delimiter);
2195  }
2196 
2197  static inline bool perform_include_all_delimiters(const type& split_opt)
2198  {
2199  return include_all_delimiters == (split_opt & include_all_delimiters);
2200  }
2201 
2202  } // namespace tokenize_options
2203 
2204  template <typename Iterator, typename DelimiterPredicate>
2206  {
2207  private:
2208 
2209  template <typename Iterartor,
2210  typename Predicate,
2211  typename T = std::pair<Iterator,Iterator> >
2212  class tokenizer_iterator : public std::iterator<std::forward_iterator_tag,T>
2213  {
2214  protected:
2215 
2216  typedef Iterator iterator;
2217  typedef const iterator const_iterator;
2218  typedef typename std::pair<iterator,iterator> range_type;
2219 
2220  public:
2221 
2222  explicit inline tokenizer_iterator(const iterator begin,
2223  const iterator end,
2224  const Predicate& predicate,
2226  : predicate_(predicate),
2227  end_(end),
2228  range_(begin,begin),
2229  current_token_(end,end),
2230  compress_delimiters_(tokenize_options::perform_compress_delimiters(tokenize_option)),
2231  include_1st_delimiter_(tokenize_options::perform_include_1st_delimiter(tokenize_option)),
2232  include_all_delimiters_(tokenize_options::perform_include_all_delimiters(tokenize_option)),
2233  include_delimiters_(include_1st_delimiter_ || include_all_delimiters_),
2234  last_token_done_(false)
2235  {
2236  if (end != begin)
2237  {
2238  this->operator++();
2239  }
2240  }
2241 
2242  inline tokenizer_iterator& operator++()
2243  {
2244  if (last_token_done_)
2245  {
2246  range_.first = range_.second;
2247  return (*this);
2248  }
2249  else if (end_ != range_.second)
2250  {
2251  range_.first = range_.second;
2252  }
2253 
2254  while (end_ != range_.second)
2255  {
2256  if (predicate_(*(range_.second)))
2257  {
2258  if (include_delimiters_)
2259  {
2260  if (include_1st_delimiter_)
2261  ++range_.second;
2262  else if (include_all_delimiters_)
2263  while ((end_ != range_.second) && predicate_(*(range_.second))) ++range_.second;
2264  current_token_ = range_;
2265  if ((!include_all_delimiters_) && compress_delimiters_)
2266  while ((end_ != range_.second) && predicate_(*(range_.second))) ++range_.second;
2267  }
2268  else
2269  {
2270  current_token_ = range_;
2271  if (compress_delimiters_)
2272  while ((end_ != (++range_.second)) && predicate_(*(range_.second))) ;
2273  else
2274  ++range_.second;
2275  }
2276  return (*this);
2277  }
2278  else
2279  ++range_.second;
2280  }
2281 
2282  if (range_.first != range_.second)
2283  {
2284  current_token_.second = range_.second;
2285  if (!last_token_done_)
2286  {
2287  if (predicate_(*(range_.second - 1)))
2288  current_token_.first = range_.second;
2289  else
2290  current_token_.first = range_.first;
2291  last_token_done_ = true;
2292  }
2293  else
2294  range_.first = range_.second;
2295  }
2296 
2297  return (*this);
2298  }
2299 
2300  inline tokenizer_iterator operator++(int)
2301  {
2302  tokenizer_iterator tmp = (*this);
2303  this->operator++();
2304  return tmp;
2305  }
2306 
2307  inline tokenizer_iterator& operator+=(const int inc)
2308  {
2309  if (inc > 0)
2310  {
2311  for (int i = 0; i < inc; ++i, ++(*this)) ;
2312  }
2313  return (*this);
2314  }
2315 
2316  inline T operator*() const
2317  {
2318  return current_token_;
2319  }
2320 
2321  inline std::string as_string() const
2322  {
2323  return std::string(current_token_.first,current_token_.second);
2324  }
2325 
2326  inline bool operator==(const tokenizer_iterator& itr) const
2327  {
2328  return (range_ == itr.range_) && (end_ == itr.end_);
2329  }
2330 
2331  inline bool operator!=(const tokenizer_iterator& itr) const
2332  {
2333  return (range_ != itr.range_) || (end_ != itr.end_);
2334  }
2335 
2336  inline tokenizer_iterator& operator=(const tokenizer_iterator& itr)
2337  {
2338  if (this != &itr)
2339  {
2340  range_ = itr.range_;
2341  current_token_ = itr.current_token_;
2342  end_ = itr.end_;
2343  compress_delimiters_ = itr.compress_delimiters_;
2344  include_1st_delimiter_ = itr.include_1st_delimiter_;
2345  include_all_delimiters_ = itr.include_all_delimiters_;
2346  include_delimiters_ = itr.include_delimiters_;
2347  last_token_done_ = itr.last_token_done_;
2348  }
2349  return (*this);
2350  }
2351 
2352  inline std::string remaining() const
2353  {
2354  return std::string(current_token_.first,end_);
2355  }
2356 
2357  protected:
2358 
2359  const Predicate& predicate_;
2360  iterator end_;
2361  range_type range_;
2362  range_type current_token_;
2363  bool compress_delimiters_;
2364  bool include_1st_delimiter_;
2365  bool include_all_delimiters_;
2366  bool include_delimiters_;
2367  bool last_token_done_;
2368  };
2369 
2370  public:
2371 
2372  typedef typename std::iterator_traits<Iterator>::value_type value_type;
2373  typedef DelimiterPredicate predicate;
2374  typedef tokenizer_iterator<Iterator,DelimiterPredicate> iterator;
2375  typedef const iterator const_iterator;
2378 
2379  inline tokenizer(const Iterator begin,
2380  const Iterator end,
2381  const DelimiterPredicate& predicate,
2382  const tokenize_options::type tokenize_options = tokenize_options::default_mode)
2383  : tokenize_options_(tokenize_options),
2384  predicate_(predicate),
2385  begin_(begin),
2386  end_(end),
2387  begin_itr_(begin_,end_,predicate_,tokenize_options_),
2388  end_itr_(end_,end_,predicate_,tokenize_options_)
2389  {}
2390 
2391  inline tokenizer(const std::string& s,
2392  const DelimiterPredicate& predicate,
2393  const tokenize_options::type tokenize_options = tokenize_options::default_mode)
2394  : tokenize_options_(tokenize_options),
2395  predicate_(predicate),
2396  begin_(s.data()),
2397  end_(s.data() + s.size()),
2398  begin_itr_(begin_,end_,predicate_,tokenize_options_),
2399  end_itr_(end_,end_,predicate_,tokenize_options_)
2400  {}
2401 
2402  inline tokenizer& operator=(const tokenizer& t)
2403  {
2404  if (this != &t)
2405  {
2406  begin_ = t.begin_;
2407  end_ = t.end_;
2408  end_itr_ = t.end_itr_;
2409  begin_itr_ = t.begin_itr_;
2410  tokenize_options_ = t.tokenize_options_;
2411  }
2412  return (*this);
2413  }
2414 
2415  inline void assign(const std::string& s) const
2416  {
2417  assign(s.data(),s.data() + s.size());
2418  }
2419 
2420  inline void assign(const std::string& s)
2421  {
2422  assign(s.data(),s.data() + s.size());
2423  }
2424 
2425  inline void assign(const Iterator begin, const Iterator end)
2426  {
2427  begin_ = begin;
2428  end_ = end;
2429  begin_itr_ = iterator(begin_,end_,predicate_,tokenize_options_);
2430  end_itr_ = iterator(end_,end_,predicate_,tokenize_options_);
2431  }
2432 
2433  inline const_iterator_ref begin() const
2434  {
2435  return begin_itr_;
2436  }
2437 
2438  inline const_iterator_ref end() const
2439  {
2440  return end_itr_;
2441  }
2442 
2443  private:
2444 
2445  tokenize_options::type tokenize_options_;
2446  const DelimiterPredicate& predicate_;
2447  Iterator begin_;
2448  Iterator end_;
2449  iterator begin_itr_;
2450  iterator end_itr_;
2451  };
2452 
2453  namespace std_string
2454  {
2455  template <typename DelimiterPredicate = single_delimiter_predicate<std::string::value_type> >
2456  struct tokenizer
2457  {
2458  typedef DelimiterPredicate predicate_type;
2459  typedef const std::string::value_type* string_iterator_type;
2462  typedef std::pair<string_iterator_type,string_iterator_type> iterator_type;
2463  };
2464 
2467 
2468  typedef std::vector<iterator_type> token_vector_type;
2469  typedef std::deque<iterator_type> token_deque_type;
2470  typedef std::list<iterator_type> token_list_type;
2471 
2472  } // namespace std_string
2473 
2474  template <typename Sequence>
2475  class range_to_type_back_inserter_iterator : public std::iterator<std::output_iterator_tag,
2476  void,
2477  void,
2478  void,
2479  void>
2480  {
2481  public:
2482 
2483  typedef typename Sequence::value_type value_type;
2484 
2485  explicit inline range_to_type_back_inserter_iterator(Sequence& sequence)
2486  : sequence_(sequence)
2487  {}
2488 
2490  : sequence_(it.sequence_)
2491  {}
2492 
2494  {
2495  if (this != &it)
2496  {
2497  this->sequence_ = it.sequence_;
2498  }
2499  return (*this);
2500  }
2501 
2502  template <typename Iterator>
2503  inline range_to_type_back_inserter_iterator& operator=(const std::pair<Iterator,Iterator>& r)
2504  {
2505  value_type t = value_type();
2506  if (string_to_type_converter(r.first,r.second,t))
2507  sequence_.push_back(t);
2508  return (*this);
2509  }
2510 
2512  {
2513  value_type t = value_type();
2514  if (string_to_type_converter(s.data(),s.data() + s.size(),t))
2515  sequence_.push_back(t);
2516  return (*this);
2517  }
2518 
2519  template <typename Iterator>
2520  inline void operator()(const std::pair<Iterator,Iterator>& r) const
2521  {
2522  value_type t;
2523  if (string_to_type_converter(r.first,r.second,t))
2524  sequence_.push_back(t);
2525  }
2526 
2527  template <typename Iterator>
2528  inline void operator()(const Iterator begin, const Iterator end)
2529  {
2530  sequence_.push_back(string_to_type_converter<value_type>(begin,end));
2531  }
2532 
2534  {
2535  return (*this);
2536  }
2537 
2539  {
2540  return (*this);
2541  }
2542 
2544  {
2545  return (*this);
2546  }
2547 
2548  private:
2549 
2550  Sequence& sequence_;
2551  };
2552 
2553  template <typename Sequence>
2555  {
2557  }
2558 
2559  template <typename Set>
2560  class range_to_type_inserter_iterator : public std::iterator<std::output_iterator_tag,
2561  void,
2562  void,
2563  void,
2564  void>
2565  {
2566  public:
2567 
2568  typedef typename Set::value_type value_type;
2569 
2570  explicit inline range_to_type_inserter_iterator(Set& set)
2571  : set_(set)
2572  {}
2573 
2575  : set_(it.set_)
2576  {}
2577 
2579  {
2580  if (this != &it)
2581  {
2582  this->set_ = it.set_;
2583  }
2584  return (*this);
2585  }
2586 
2587  template <typename Iterator>
2588  inline range_to_type_inserter_iterator& operator=(const std::pair<Iterator,Iterator>& r)
2589  {
2590  value_type t;
2591  if (string_to_type_converter(r.first,r.second,t))
2592  set_.insert(t);
2593  return (*this);
2594  }
2595 
2596  template <typename Iterator>
2597  inline void operator()(const std::pair<Iterator,Iterator>& r)
2598  {
2599  value_type t;
2600  if (string_to_type_converter(r.first,r.second,t))
2601  set_.insert(t);
2602  }
2603 
2605  {
2606  return (*this);
2607  }
2608 
2610  {
2611  return (*this);
2612  }
2613 
2615  {
2616  return (*this);
2617  }
2618 
2619  private:
2620 
2621  Set& set_;
2622  };
2623 
2624  template <typename Set>
2626  {
2628  }
2629 
2630  template <typename Container>
2631  class range_to_type_push_inserter_iterator : public std::iterator<std::output_iterator_tag,
2632  void,
2633  void,
2634  void,
2635  void>
2636  {
2637  public:
2638 
2639  typedef typename Container::value_type value_type;
2640 
2641  explicit inline range_to_type_push_inserter_iterator(Container& container)
2642  : container_(container)
2643  {}
2644 
2646  : container_(it.container_)
2647  {}
2648 
2650  {
2651  if (this != &it)
2652  {
2653  this->container_ = it.container_;
2654  }
2655  return (*this);
2656  }
2657 
2658  template <typename Iterator>
2659  inline range_to_type_push_inserter_iterator& operator=(const std::pair<Iterator,Iterator>& r)
2660  {
2661  value_type t;
2662  if (string_to_type_converter(r.first,r.second,t))
2663  container_.push(t);
2664  return (*this);
2665  }
2666 
2667  template <typename Iterator>
2668  inline void operator()(const std::pair<Iterator,Iterator>& r)
2669  {
2670  value_type t;
2671  if (string_to_type_converter(r.first,r.second,t))
2672  container_.push(t);
2673  }
2674 
2676  {
2677  return (*this);
2678  }
2679 
2681  {
2682  return (*this);
2683  }
2684 
2686  {
2687  return (*this);
2688  }
2689 
2690  private:
2691 
2692  Container& container_;
2693  };
2694 
2695  template <typename Container>
2697  {
2699  }
2700 
2701  template <typename Sequence>
2702  class back_inserter_with_valuetype_iterator : public std::iterator<std::output_iterator_tag,
2703  typename Sequence::value_type,
2704  void,
2705  void,
2706  void>
2707  {
2708  public:
2709 
2710  explicit inline back_inserter_with_valuetype_iterator(Sequence& sequence)
2711  : sequence_(sequence)
2712  {}
2713 
2715  : sequence_(it.sequence_)
2716  {}
2717 
2719  {
2720  if (this != &it)
2721  {
2722  this->sequence_ = it.sequence_;
2723  }
2724  return (*this);
2725  }
2726 
2727  inline back_inserter_with_valuetype_iterator& operator=(const typename Sequence::value_type& v)
2728  {
2729  sequence_.push_back(v);
2730  return (*this);
2731  }
2732 
2733  inline void operator()(const typename Sequence::value_type& v)
2734  {
2735  sequence_.push_back(v);
2736  }
2737 
2739  {
2740  return (*this);
2741  }
2742 
2744  {
2745  return (*this);
2746  }
2747 
2749  {
2750  return (*this);
2751  }
2752 
2753  private:
2754 
2755  Sequence& sequence_;
2756  };
2757 
2758  template <typename Sequence>
2760  {
2762  }
2763 
2764  template <typename Set>
2765  class inserter_with_valuetype_iterator : public std::iterator<std::output_iterator_tag,
2766  typename Set::value_type,
2767  void,
2768  void,
2769  void>
2770  {
2771  public:
2772 
2773  explicit inline inserter_with_valuetype_iterator(Set& set)
2774  : set_(set)
2775  {}
2776 
2778  : set_(itr.set_)
2779  {}
2780 
2782  {
2783  if (this != &itr)
2784  {
2785  this->set_ = itr.set_;
2786  }
2787  return (*this);
2788  }
2789 
2790  inline inserter_with_valuetype_iterator& operator=(const typename Set::value_type& v)
2791  {
2792  set_.insert(v);
2793  return (*this);
2794  }
2795 
2796  inline void operator()(const typename Set::value_type& v)
2797  {
2798  set_.insert(v);
2799  }
2800 
2802  {
2803  return (*this);
2804  }
2805 
2807  {
2808  return (*this);
2809  }
2810 
2812  {
2813  return (*this);
2814  }
2815 
2816  private:
2817 
2818  Set& set_;
2819  };
2820 
2821  template <typename Set>
2823  {
2825  }
2826 
2827  template <typename Container>
2828  class push_inserter_iterator : public std::iterator<std::output_iterator_tag,
2829  void,
2830  void,
2831  void,
2832  void>
2833  {
2834  public:
2835 
2836  explicit inline push_inserter_iterator(Container& container)
2837  : container_(container)
2838  {}
2839 
2841  {
2842  if (this != &itr)
2843  {
2844  this->container_ = itr.container_;
2845  }
2846  return (*this);
2847  }
2848 
2849  inline push_inserter_iterator<Container>& operator=(typename Container::const_reference v)
2850  {
2851  container_.push(v);
2852  return (*this);
2853  }
2854 
2856  {
2857  return (*this);
2858  }
2859 
2861  {
2862  return (*this);
2863  }
2864 
2866  {
2867  return (*this);
2868  }
2869 
2870  private:
2871 
2872  Container& container_;
2873  };
2874 
2875  template <typename Container>
2877  {
2879  }
2880 
2881  template <typename T>
2882  class range_to_ptr_type_iterator : public std::iterator<std::output_iterator_tag,
2883  void,
2884  void,
2885  void,
2886  void>
2887  {
2888  public:
2889 
2890  typedef T value_type;
2891 
2892  explicit inline range_to_ptr_type_iterator(T* pointer, std::size_t& insert_count)
2893  : pointer_(pointer),
2894  insert_count_(insert_count)
2895  {}
2896 
2898  : pointer_(it.pointer_)
2899  {}
2900 
2902  {
2903  if (this != &it)
2904  {
2905  this->pointer_ = it.pointer_;
2906  }
2907  return (*this);
2908  }
2909 
2910  template <typename Iterator>
2911  inline range_to_ptr_type_iterator& operator=(const std::pair<Iterator,Iterator>& r)
2912  {
2913  value_type t = value_type();
2914  if (string_to_type_converter(r.first,r.second,t))
2915  {
2916  (*pointer_) = t;
2917  ++pointer_;
2918  ++insert_count_;
2919  }
2920  return (*this);
2921  }
2922 
2924  {
2925  value_type t = value_type();
2926  if (string_to_type_converter(s.data(),s.data() + s.size(),t))
2927  {
2928  (*pointer_) = t;
2929  ++pointer_;
2930  ++insert_count_;
2931  }
2932  return (*this);
2933  }
2934 
2935  template <typename Iterator>
2936  inline void operator()(const std::pair<Iterator,Iterator>& r) const
2937  {
2938  value_type t;
2939  if (string_to_type_converter(r.first,r.second,t))
2940  {
2941  (*pointer_) = t;
2942  ++pointer_;
2943  ++insert_count_;
2944  }
2945  }
2946 
2947  template <typename Iterator>
2948  inline void operator()(const Iterator begin, const Iterator end)
2949  {
2950  (*pointer_) = string_to_type_converter<T>(begin,end);
2951  ++pointer_;
2952  ++insert_count_;
2953  }
2954 
2956  {
2957  return (*this);
2958  }
2959 
2961  {
2962  return (*this);
2963  }
2964 
2966  {
2967  return (*this);
2968  }
2969 
2970  private:
2971 
2972  T* pointer_;
2973  std::size_t& insert_count_;
2974  };
2975 
2976  template <typename T>
2977  inline range_to_ptr_type_iterator<T> range_to_ptr_type(T* pointer, std::size_t& insert_count)
2978  {
2979  return (range_to_ptr_type_iterator<T>(pointer,insert_count));
2980  }
2981 
2982  template <typename T>
2984  {
2985  static std::size_t insert_count = 0;
2986  return (range_to_ptr_type_iterator<T>(pointer,insert_count));
2987  }
2988 
2989  template <typename T>
2990  class counting_back_inserter_iterator : public std::iterator<std::output_iterator_tag,
2991  T,
2992  void,
2993  void,
2994  void>
2995  {
2996  public:
2997 
2998  explicit inline counting_back_inserter_iterator(std::size_t& counter)
2999  : counter_(counter)
3000  {}
3001 
3003  : counter_(itr.counter_)
3004  {}
3005 
3007  {
3008  if (this != &itr)
3009  {
3010  this->counter_ = itr.counter_;
3011  }
3012  return (*this);
3013  }
3014 
3016  {
3017  ++counter_;
3018  return (*this);
3019  }
3020 
3021  inline void operator()(const T&)
3022  {
3023  ++counter_;
3024  }
3025 
3027  {
3028  return (*this);
3029  }
3030 
3032  {
3033  return (*this);
3034  }
3035 
3037  {
3038  return (*this);
3039  }
3040 
3041  private:
3042 
3043  std::size_t& counter_;
3044  };
3045 
3046  template <typename T>
3048  {
3049  return (counting_back_inserter_iterator<T>(counter_));
3050  }
3051 
3052  template <typename Function>
3053  class functional_inserter_iterator : public std::iterator<std::output_iterator_tag,
3054  void,
3055  void,
3056  void,
3057  void>
3058  {
3059  public:
3060 
3061  explicit inline functional_inserter_iterator(Function function)
3062  : function_(function)
3063  {}
3064 
3066  : function_(it.function_)
3067  {}
3068 
3070  {
3071  if (this != &it)
3072  {
3073  this->function_ = it.function_;
3074  }
3075  return (*this);
3076  }
3077 
3078  template <typename T>
3080  {
3081  function_(t);
3082  return (*this);
3083  }
3084 
3085  template <typename T>
3086  inline void operator()(const T& t)
3087  {
3088  function_(t);
3089  }
3090 
3092  {
3093  return (*this);
3094  }
3095 
3097  {
3098  return (*this);
3099  }
3100 
3102  {
3103  return (*this);
3104  }
3105 
3106  private:
3107 
3108  Function function_;
3109  };
3110 
3111  template <typename Function>
3113  {
3114  return (functional_inserter_iterator<Function>(function));
3115  }
3116 
3117  namespace split_options
3118  {
3119  typedef std::size_t type;
3120  enum
3121  {
3126  };
3127 
3128  static inline bool perform_compress_delimiters(const type& split_opt)
3129  {
3130  return compress_delimiters == (split_opt & compress_delimiters);
3131  }
3132 
3133  static inline bool perform_include_1st_delimiter(const type& split_opt)
3134  {
3135  return include_1st_delimiter == (split_opt & include_1st_delimiter);
3136  }
3137 
3138  static inline bool perform_include_all_delimiters(const type& split_opt)
3139  {
3140  return include_all_delimiters == (split_opt & include_all_delimiters);
3141  }
3142 
3143  } // namespace split_options
3144 
3145  template <typename DelimiterPredicate,
3146  typename Iterator,
3147  typename OutputIterator>
3148  inline std::size_t split(const DelimiterPredicate& delimiter,
3149  const Iterator begin,
3150  const Iterator end,
3151  OutputIterator out,
3152  const split_options::type split_option = split_options::default_mode)
3153  {
3154  if (begin == end) return 0;
3155  std::size_t token_count = 0;
3156  std::pair<Iterator,Iterator> range(begin,begin);
3157  const bool compress_delimiters = split_options::perform_compress_delimiters(split_option);
3158  const bool include_1st_delimiter = split_options::perform_include_1st_delimiter(split_option);
3159  const bool include_all_delimiters = (!include_1st_delimiter) && split_options::perform_include_all_delimiters(split_option);
3160  const bool include_delimiters = include_1st_delimiter || include_all_delimiters;
3161 
3162  while (end != range.second)
3163  {
3164  if (delimiter(*range.second))
3165  {
3166  if (include_delimiters)
3167  {
3168  if (include_1st_delimiter)
3169  ++range.second;
3170  else if (include_all_delimiters)
3171  while ((end != range.second) && delimiter(*range.second)) ++range.second;
3172  (*out) = range;
3173  ++out;
3174  if ((!include_all_delimiters) && compress_delimiters)
3175  while ((end != range.second) && delimiter(*range.second)) ++range.second;
3176  }
3177  else
3178  {
3179  (*out) = range;
3180  ++out;
3181  if (compress_delimiters)
3182  while ((end != (++range.second)) && delimiter(*range.second)) ;
3183  else
3184  ++range.second;
3185  }
3186  ++token_count;
3187  range.first = range.second;
3188  }
3189  else
3190  ++range.second;
3191  }
3192 
3193  if ((range.first != range.second) || delimiter(*(range.second - 1)))
3194  {
3195  (*out) = range;
3196  ++out;
3197  ++token_count;
3198  }
3199 
3200  return token_count;
3201  }
3202 
3203  template <typename DelimiterPredicate,
3204  typename Iterator,
3205  typename OutputIterator>
3206  inline std::size_t split(const DelimiterPredicate& delimiter,
3207  const std::pair<Iterator,Iterator>& range,
3208  OutputIterator out,
3209  const split_options::type split_option = split_options::default_mode)
3210  {
3211  return split(delimiter,
3212  range.first,range.second,
3213  out,
3214  split_option);
3215  }
3216 
3217  template <typename DelimiterPredicate,
3218  typename Iterator,
3219  typename OutputIterator>
3220  inline std::size_t split(const char* delimiters,
3221  const std::pair<Iterator,Iterator>& range,
3222  OutputIterator out,
3223  const split_options::type split_option = split_options::default_mode)
3224  {
3225  if (1 == details::strnlength(delimiters,256))
3227  range.first,range.second,
3228  out,
3229  split_option);
3230  else
3231  return split(multiple_char_delimiter_predicate(delimiters),
3232  range.first,range.second,
3233  out,
3234  split_option);
3235  }
3236 
3237  template <typename DelimiterPredicate,
3238  typename Iterator,
3239  typename OutputIterator>
3240  inline std::size_t split(const std::string& delimiters,
3241  const std::pair<Iterator,Iterator>& range,
3242  OutputIterator out,
3243  const split_options::type split_option = split_options::default_mode)
3244  {
3245  if (1 == delimiters.size())
3247  range.first,range.second,
3248  out,
3249  split_option);
3250  else
3251  return split(multiple_char_delimiter_predicate(delimiters),
3252  range.first,range.second,
3253  out,
3254  split_option);
3255  }
3256 
3257  template <typename OutputIterator>
3258  inline std::size_t split(const char* delimiters,
3259  const std::string& str,
3260  OutputIterator out,
3261  const split_options::type& split_option = split_options::default_mode)
3262  {
3263  if (1 == details::strnlength(delimiters,256))
3265  str.data(), str.data() + str.size(),
3266  out,
3267  split_option);
3268  else
3269  return split(multiple_char_delimiter_predicate(delimiters),
3270  str.data(), str.data() + str.size(),
3271  out,
3272  split_option);
3273  }
3274 
3275  template <typename OutputIterator>
3276  inline std::size_t split(const std::string& delimiters,
3277  const std::string& str,
3278  OutputIterator out,
3279  const split_options::type& split_option = split_options::default_mode)
3280  {
3281  if (1 == delimiters.size())
3283  str.data(), str.data() + str.size(),
3284  out,
3285  split_option);
3286  else
3287  return split(multiple_char_delimiter_predicate(delimiters),
3288  str.data(), str.data() + str.size(),
3289  out,
3290  split_option);
3291  }
3292 
3293  template <typename OutputIterator>
3294  inline std::size_t split(const std::string::value_type delimiter,
3295  const std::string& str,
3296  OutputIterator out,
3297  const split_options::type& split_option = split_options::default_mode)
3298  {
3300  str.data(), str.data() + str.size(),
3301  out,
3302  split_option);
3303  }
3304 
3305  template <typename Allocator,
3306  template <typename,typename> class Sequence>
3307  inline std::size_t split(const char* delimiters,
3308  const std::string& str,
3309  Sequence<std::pair<const char*, const char*>,Allocator>& sequence,
3310  const split_options::type& split_option = split_options::default_mode)
3311  {
3312  if (1 == details::strnlength(delimiters,256))
3314  str.data(), str.data() + str.size(),
3315  std::back_inserter(sequence),
3316  split_option);
3317  else
3318  return split(multiple_char_delimiter_predicate(delimiters),
3319  str.data(), str.data() + str.size(),
3320  std::back_inserter(sequence),
3321  split_option);
3322  }
3323 
3324  template <typename Allocator,
3325  template <typename,typename> class Sequence>
3326  inline std::size_t split(const std::string& delimiters,
3327  const std::string& str,
3328  Sequence<std::pair<const char*, const char*>,Allocator>& sequence,
3329  const split_options::type& split_option = split_options::default_mode)
3330  {
3331  if (1 == delimiters.size())
3333  str.data(), str.data() + str.size(),
3334  std::back_inserter(sequence),
3335  split_option);
3336  else
3337  return split(multiple_char_delimiter_predicate(delimiters),
3338  str.data(), str.data() + str.size(),
3339  std::back_inserter(sequence),
3340  split_option);
3341  }
3342 
3343  template <typename DelimiterPredicate,
3344  typename OutputIterator>
3345  inline std::size_t split(const DelimiterPredicate& delimiter,
3346  const std::string& str,
3347  OutputIterator out,
3348  const split_options::type& split_option = split_options::default_mode)
3349  {
3350  return split(delimiter,
3351  str.data(), str.data() + str.size(),
3352  out,
3353  split_option);
3354  }
3355 
3356  template <typename DelimiterPredicate,
3357  typename Iterator,
3358  typename OutputIterator>
3359  inline std::size_t split_n(const DelimiterPredicate& delimiter,
3360  const Iterator begin,
3361  const Iterator end,
3362  const std::size_t& token_count,
3363  OutputIterator out,
3364  const split_options::type& split_option = split_options::default_mode)
3365  {
3366  if (0 == token_count) return 0;
3367  if (begin == end) return 0;
3368  std::size_t match_count = 0;
3369  std::pair<Iterator,Iterator> range(begin,begin);
3370  const bool compress_delimiters = split_options::perform_compress_delimiters(split_option);
3371  const bool include_1st_delimiter = split_options::perform_include_1st_delimiter(split_option);
3372  const bool include_all_delimiters = (!include_1st_delimiter) && split_options::perform_include_all_delimiters(split_option);
3373  const bool include_delimiters = include_1st_delimiter || include_all_delimiters;
3374 
3375  while (end != range.second)
3376  {
3377  if (delimiter(*range.second))
3378  {
3379  if (include_delimiters)
3380  {
3381  ++range.second;
3382  (*out) = range;
3383  ++out;
3384  if (++match_count >= token_count)
3385  return match_count;
3386  if (compress_delimiters)
3387  while ((end != range.second) && delimiter(*range.second)) ++range.second;
3388  }
3389  else
3390  {
3391  (*out) = range;
3392  ++out;
3393  if (++match_count >= token_count)
3394  return match_count;
3395  if (compress_delimiters)
3396  while ((end != (++range.second)) && delimiter(*range.second)) ;
3397  else
3398  ++range.second;
3399  }
3400  range.first = range.second;
3401  }
3402  else
3403  ++range.second;
3404  }
3405 
3406  if ((range.first != range.second) || delimiter(*(range.second - 1)))
3407  {
3408  (*out) = range;
3409  ++out;
3410  ++match_count;
3411  }
3412 
3413  return match_count;
3414  }
3415 
3416  template <typename OutputIterator>
3417  inline std::size_t split_n(const char* delimiters,
3418  const std::string& str,
3419  const std::size_t& token_count,
3420  OutputIterator out,
3421  const split_options::type& split_option = split_options::default_mode)
3422  {
3423  return split_n(multiple_char_delimiter_predicate(delimiters),
3424  str.data(), str.data() + str.size(),
3425  token_count,
3426  out,
3427  split_option);
3428  }
3429 
3430  template <typename OutputIterator>
3431  inline std::size_t split_n(const std::string& delimiters,
3432  const std::string& str,
3433  const std::size_t& token_count,
3434  OutputIterator out,
3435  const split_options::type& split_option = split_options::default_mode)
3436  {
3437  if (1 == delimiters.size())
3439  str.data(), str.data() + str.size(),
3440  token_count,
3441  out,
3442  split_option);
3443  else
3444  return split_n(multiple_char_delimiter_predicate(delimiters),
3445  str.data(), str.data() + str.size(),
3446  token_count,
3447  out,
3448  split_option);
3449  }
3450 
3451  template <typename InputIterator, typename OutputIterator>
3452  inline std::size_t split_n(const std::string& delimiters,
3453  const InputIterator begin,
3454  const InputIterator end,
3455  const std::size_t& token_count,
3456  OutputIterator out,
3457  const split_options::type& split_option = split_options::default_mode)
3458  {
3459  typedef typename details::is_valid_iterator<InputIterator>::type itr_type;
3460  if (1 == delimiters.size())
3462  begin,end,
3463  token_count,
3464  out,
3465  split_option);
3466  else
3467  return split_n(multiple_char_delimiter_predicate(delimiters),
3468  begin,end,
3469  token_count,
3470  out,
3471  split_option);
3472  }
3473 
3474  template <typename OutputIterator>
3475  inline std::size_t split_n(const std::string::value_type delimiter,
3476  const std::string& str,
3477  const std::size_t& token_count,
3478  OutputIterator out,
3479  const split_options::type& split_option = split_options::default_mode)
3480  {
3482  str.data(),str.data() + str.size(),
3483  token_count,
3484  out,
3485  split_option);
3486  }
3487 
3488  template <typename DelimiterPredicate,
3489  typename OutputIterator>
3490  inline std::size_t split_n(const DelimiterPredicate& delimiter,
3491  const std::string& str,
3492  const std::size_t& token_count,
3493  OutputIterator out,
3494  const split_options::type& split_option = split_options::default_mode)
3495  {
3496  return split_n(delimiter,
3497  str.data(),str.data() + str.size(),
3498  token_count,
3499  out,
3500  split_option);
3501  }
3502 
3503  #ifdef strtk_enable_regex
3504 
3505  static const std::string uri_expression ("((https?|ftp)\\://((\\[?(\\d{1,3}\\.){3}\\d{1,3}\\]?)|(([-a-zA-Z0-9]+\\.)+[a-zA-Z]{2,4}))(\\:\\d+)?(/[-a-zA-Z0-9._?,+&amp;%$#=~\\\\]+)*/?)");
3506  static const std::string email_expression ("([\\w\\-\\.]+)@((\\[([0-9]{1,3}\\.){3}[0-9]{1,3}\\])|(([\\w\\-]+\\.)+)([a-zA-Z]{2,4}))");
3507  static const std::string ip_expression ("(([0-2]*[0-9]+[0-9]+)\\.([0-2]*[0-9]+[0-9]+)\\.([0-2]*[0-9]+[0-9]+)\\.([0-2]*[0-9]+[0-9]+))");
3508  static const std::string ieee754_expression ("([-+]?((\\.[0-9]+|[0-9]+\\.[0-9]+)([eE][-+][0-9]+)?|[0-9]+))");
3509 
3510  namespace regex_match_mode
3511  {
3512  enum type
3513  {
3515  match_1 = 1,
3516  match_2 = 2,
3517  match_3 = 3,
3518  match_4 = 4,
3519  match_5 = 5,
3520  match_6 = 6,
3521  match_7 = 7,
3522  match_8 = 8,
3524  };
3525  }
3526 
3527  template <typename InputIterator, typename OutputIterator>
3528  inline std::size_t split_regex(const boost::regex& delimiter_expression,
3529  const InputIterator begin,
3530  const InputIterator end,
3531  OutputIterator out,
3533  {
3534  boost::regex_iterator<InputIterator> itr(begin,end,delimiter_expression);
3535  boost::regex_iterator<InputIterator> itr_end;
3536  std::pair<InputIterator,InputIterator> range(begin,begin);
3537  std::size_t match_count = 0;
3538  while (itr_end != itr)
3539  {
3540  range.first = (*itr)[mode].first;
3541  range.second = (*itr)[mode].second;
3542  (*out) = range;
3543  ++out;
3544  ++itr;
3545  ++match_count;
3546  }
3547  return match_count;
3548  }
3549 
3550  template <typename InputIterator, typename OutputIterator>
3551  inline std::size_t split_regex(const std::string& delimiter_expression,
3552  const InputIterator begin,
3553  const InputIterator end,
3554  OutputIterator out,
3556  {
3557  const boost::regex regex_expression(delimiter_expression);
3558  return split_regex(regex_expression,
3559  begin,end,
3560  out,
3561  mode);
3562  }
3563 
3564  template <typename OutputIterator>
3565  inline std::size_t split_regex(const std::string& delimiter_expression,
3566  const std::string& text,
3567  OutputIterator out,
3569  {
3570  return split_regex(delimiter_expression,
3571  text.begin(),text.end(),
3572  out,
3573  mode);
3574  }
3575 
3576  template <typename OutputIterator>
3577  inline std::size_t split_regex(const boost::regex& delimiter_expression,
3578  const std::string& text,
3579  OutputIterator out,
3581  {
3582  return split_regex(delimiter_expression,
3583  text.begin(),text.end(),
3584  out,
3585  mode);
3586  }
3587 
3588  template <typename InputIterator, typename OutputIterator>
3589  inline std::size_t split_regex_n(const boost::regex& delimiter_expression,
3590  const InputIterator begin,
3591  const InputIterator end,
3592  const std::size_t& token_count,
3593  OutputIterator out,
3595  {
3596  boost::sregex_iterator itr(begin,end,delimiter_expression);
3597  const boost::sregex_iterator itr_end;
3598  std::pair<InputIterator,InputIterator> range(begin,begin);
3599  std::size_t match_count = 0;
3600  while (itr_end != itr)
3601  {
3602  range.first = (*itr)[mode].first;
3603  range.second = (*itr)[mode].second;
3604  (*out) = range;
3605  ++out;
3606  ++itr;
3607  if (++match_count >= token_count)
3608  return match_count;
3609  }
3610  return match_count;
3611  }
3612 
3613  template <typename InputIterator, typename OutputIterator>
3614  inline std::size_t split_regex_n(const std::string& delimiter_expression,
3615  const InputIterator begin,
3616  const InputIterator end,
3617  const std::size_t& token_count,
3618  OutputIterator out,
3620  {
3621  const boost::regex regex_expression(delimiter_expression);
3622  return split_regex_n(regex_expression,
3623  begin,end,
3624  token_count,
3625  out,
3626  mode);
3627  }
3628 
3629  template <typename OutputIterator>
3630  inline std::size_t split_regex_n(const std::string& delimiter_expression,
3631  const std::string& text,
3632  const std::size_t& token_count,
3633  OutputIterator out,
3635  {
3636  return split_regex_n(delimiter_expression,
3637  text.begin(),text.end(),
3638  token_count,
3639  out,
3640  mode);
3641  }
3642 
3643  template <typename OutputIterator>
3644  inline std::size_t split_regex_n(const boost::regex& delimiter_expression,
3645  const std::string& text,
3646  const std::size_t& token_count,
3647  OutputIterator out,
3649  {
3650  return split_regex_n(delimiter_expression,
3651  text.begin(),text.end(),
3652  token_count,
3653  out,
3654  mode);
3655  }
3656 
3657  #endif // strtk_enable_regex
3658 
3659  template <const std::size_t offset_list_size>
3661  {
3662  public:
3663 
3664  offset_predicate(const int offset_list[], const bool rotate = false)
3665  : rotate_(rotate),
3666  current_index_(0)
3667  {
3668  std::copy(offset_list, offset_list + offset_list_size, offset_list_);
3669  offset_list_[offset_list_size] = 0;
3670  }
3671 
3672  inline bool operator!() const
3673  {
3674  return (0 == offset_list_size);
3675  }
3676 
3677  inline void reset() const
3678  {
3679  current_index_ = 0;
3680  }
3681 
3682  inline std::size_t size() const
3683  {
3684  return offset_list_size;
3685  }
3686 
3687  inline int next() const
3688  {
3689  int result = offset_list_[current_index_++];
3690  if (rotate_ && (current_index_ >= offset_list_size))
3691  {
3692  current_index_ = 0;
3693  }
3694  return result;
3695  }
3696 
3697  private:
3698 
3699  bool rotate_;
3700  mutable std::size_t current_index_;
3701  int offset_list_[offset_list_size + 1];
3702  };
3703 
3704  inline offset_predicate<12> offsets(const int& v1, const int& v2, const int& v3,
3705  const int& v4, const int& v5, const int& v6,
3706  const int& v7, const int& v8, const int& v9,
3707  const int& v10, const int& v11, const int& v12,
3708  const bool& rotate = false)
3709  {
3710  const int offset_list[12] = { v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12 };
3711  return offset_predicate<12>(offset_list,rotate);
3712  }
3713 
3714  inline offset_predicate<11> offsets(const int& v1, const int& v2, const int& v3,
3715  const int& v4, const int& v5, const int& v6,
3716  const int& v7, const int& v8, const int& v9,
3717  const int& v10, const int& v11,
3718  const bool& rotate = false)
3719  {
3720  const int offset_list[11] = { v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11 };
3721  return offset_predicate<11>(offset_list,rotate);
3722  }
3723 
3724  inline offset_predicate<10> offsets(const int& v1, const int& v2, const int& v3,
3725  const int& v4, const int& v5, const int& v6,
3726  const int& v7, const int& v8, const int& v9,
3727  const int& v10, const bool& rotate = false)
3728  {
3729  const int offset_list[10] = { v1, v2, v3, v4, v5, v6, v7, v8, v9, v10 };
3730  return offset_predicate<10>(offset_list,rotate);
3731  }
3732 
3733  inline offset_predicate<9> offsets(const int& v1, const int& v2, const int& v3,
3734  const int& v4, const int& v5, const int& v6,
3735  const int& v7, const int& v8, const int& v9,
3736  const bool& rotate = false)
3737  {
3738  const int offset_list[9] = { v1, v2, v3, v4, v5, v6, v7, v8, v9 };
3739  return offset_predicate<9>(offset_list,rotate);
3740  }
3741 
3742  inline offset_predicate<8> offsets(const int& v1, const int& v2, const int& v3,
3743  const int& v4, const int& v5, const int& v6,
3744  const int& v7, const int& v8, const bool& rotate = false)
3745  {
3746  const int offset_list[8] = { v1, v2, v3, v4, v5, v6, v7, v8 };
3747  return offset_predicate<8>(offset_list,rotate);
3748  }
3749 
3750  inline offset_predicate<7> offsets(const int& v1, const int& v2, const int& v3,
3751  const int& v4, const int& v5, const int& v6,
3752  const int& v7, const bool& rotate = false)
3753  {
3754  const int offset_list[7] = { v1, v2, v3, v4, v5, v6, v7 };
3755  return offset_predicate<7>(offset_list,rotate);
3756  }
3757 
3758  inline offset_predicate<6> offsets(const int& v1, const int& v2, const int& v3,
3759  const int& v4, const int& v5, const int& v6,
3760  const bool& rotate = false)
3761  {
3762  const int offset_list[6] = { v1, v2, v3, v4, v5, v6 };
3763  return offset_predicate<6>(offset_list,rotate);
3764  }
3765 
3766  inline offset_predicate<5> offsets(const int& v1, const int& v2, const int& v3,
3767  const int& v4, const int& v5, const bool& rotate = false)
3768  {
3769  const int offset_list[5] = { v1, v2, v3, v4, v5 };
3770  return offset_predicate<5>(offset_list,rotate);
3771  }
3772 
3773  inline offset_predicate<4> offsets(const int& v1, const int& v2, const int& v3,
3774  const int& v4, const bool& rotate = false)
3775  {
3776  const int offset_list[4] = { v1, v2, v3, v4 };
3777  return offset_predicate<4>(offset_list,rotate);
3778  }
3779 
3780  inline offset_predicate<3> offsets(const int& v1, const int& v2, const int& v3,
3781  const bool& rotate = false)
3782  {
3783  const int offset_list[3] = { v1, v2, v3 };
3784  return offset_predicate<3>(offset_list,rotate);
3785  }
3786 
3787  inline offset_predicate<2> offsets(const int& v1, const int& v2, const bool& rotate = false)
3788  {
3789  const int offset_list[2] = { v1, v2 };
3790  return offset_predicate<2>(offset_list,rotate);
3791  }
3792 
3793  inline offset_predicate<1> offsets(const int& v1,
3794  const bool& rotate = false)
3795  {
3796  const int offset_list[1] = { v1 };
3797  return offset_predicate<1>(offset_list,rotate);
3798  }
3799 
3800  template <typename OffsetPredicate,
3801  typename InputIterator,
3802  typename OutputIterator>
3803  inline std::size_t offset_splitter(const InputIterator begin,
3804  const InputIterator end,
3805  const OffsetPredicate& offset,
3806  OutputIterator out)
3807  {
3808  std::size_t length = 0;
3809  if (0 == (length = std::distance(begin,end))) return 0;
3810  std::pair<InputIterator,InputIterator> range(begin,begin);
3811  std::size_t match_count = 0;
3812  int offset_length = 0;
3813  std::size_t increment_amount = 0;
3814  while ((end != range.second) && (0 < (offset_length = offset.next())))
3815  {
3816  increment_amount = std::min<std::size_t>(length,offset_length);
3817  range.first = range.second;
3818  range.second += increment_amount;
3819  length -= increment_amount;
3820  (*out) = range;
3821  ++out;
3822  ++match_count;
3823  }
3824  return match_count;
3825  }
3826 
3827  template <typename OffsetPredicate,
3828  typename OutputIterator>
3829  inline std::size_t offset_splitter(const std::string& str,
3830  const OffsetPredicate& offset,
3831  OutputIterator out)
3832  {
3833  return offset_splitter(str.data(),str.data() + str.size(),offset,out);
3834  }
3835 
3836  template <typename InputIterator,
3837  typename Predicate,
3838  typename OutputPair>
3839  inline bool split_pair(const InputIterator begin,
3840  const InputIterator end,
3841  const Predicate& delimiter,
3842  OutputPair& v1,
3843  OutputPair& v2)
3844  {
3845  if (0 == std::distance(begin,end)) return false;
3846 
3847  InputIterator itr = begin;
3848 
3849  while (end != itr)
3850  {
3851  if (delimiter(*itr))
3852  {
3853  v1 = std::make_pair(begin,itr);
3854  ++itr;
3855  if (0 != std::distance(itr,end))
3856  {
3857  v2 = std::make_pair(itr,end);
3858  return true;
3859  }
3860  else
3861  return false;
3862  }
3863  else
3864  ++itr;
3865  }
3866 
3867  return false;
3868  }
3869 
3870  inline bool split_pair(const std::string::value_type delimiter,
3871  const std::string& str,
3872  std::pair<const char*,const char*>& v1,
3873  std::pair<const char*,const char*>& v2)
3874  {
3875  return split_pair(str.data(),
3876  str.data() + str.size(),
3878  v1,
3879  v2);
3880  }
3881 
3882  template <typename DelimiterPredicate>
3883  inline bool split_pair(const DelimiterPredicate& delimiter,
3884  const std::string& str,
3885  std::pair<const char*,const char*>& v1,
3886  std::pair<const char*,const char*>& v2)
3887  {
3888  return split_pair(str.data(),
3889  str.data() + str.size(),
3890  delimiter,
3891  v1,
3892  v2);
3893  }
3894 
3895  template <typename Function>
3896  inline std::size_t for_each_token(const std::string& buffer,
3897  const std::string& delimiters,
3898  Function function)
3899  {
3900  return split(delimiters,
3901  buffer,
3902  strtk::functional_inserter<Function>(function));
3903  }
3904 
3905  template <typename Function>
3906  inline std::size_t for_each_token(const std::string& buffer,
3907  const char* delimiters,
3908  Function function)
3909  {
3910  return split(delimiters,
3911  buffer,
3912  strtk::functional_inserter<Function>(function));
3913  }
3914 
3915  template <typename InputIterator>
3916  inline std::size_t count_consecutive_duplicates(const InputIterator begin, const InputIterator end)
3917  {
3918  if (std::distance(begin,end) < 2) return 0;
3919  InputIterator prev = begin;
3920  InputIterator itr = begin;
3921  std::size_t count = 0;
3922  while (end != ++itr)
3923  {
3924  if ((*prev) == (*itr))
3925  ++count;
3926  else
3927  prev = itr;
3928  }
3929  return count;
3930  }
3931 
3932  template <typename T,
3933  typename Allocator,
3934  template <typename,typename> class Sequence>
3935  inline T min_of_cont(const Sequence<T,Allocator>& sequence)
3936  {
3937  return (*std::min_element(sequence.begin(),sequence.end()));
3938  }
3939 
3940  template <typename T,
3941  typename Comparator,
3942  typename Allocator>
3943  inline T min_of_cont(const std::set<T,Comparator,Allocator>& set)
3944  {
3945  return (*set.begin());
3946  }
3947 
3948  template <typename T,
3949  typename Comparator,
3950  typename Allocator>
3951  inline T min_of_cont(const std::multiset<T,Comparator,Allocator>& multiset)
3952  {
3953  return (*multiset.begin());
3954  }
3955 
3956  template <typename T,
3957  typename Allocator,
3958  template <typename,typename> class Sequence>
3959  inline T max_of_cont(const Sequence<T,Allocator>& sequence)
3960  {
3961  return (*std::max_element(sequence.begin(),sequence.end()));
3962  }
3963 
3964  template <typename T,
3965  typename Comparator,
3966  typename Allocator>
3967  inline T max_of_cont(const std::set<T,Comparator,Allocator>& set)
3968  {
3969  return (*set.rbegin());
3970  }
3971 
3972  template <typename T,
3973  typename Comparator,
3974  typename Allocator>
3975  inline T max_of_cont(const std::multiset<T,Comparator,Allocator>& multiset)
3976  {
3977  return (*multiset.rbegin());
3978  }
3979 
3980  template <typename InputIterator>
3981  inline void min_max_of_range(const InputIterator begin, const InputIterator end,
3982  typename std::iterator_traits<InputIterator>::value_type& min_value,
3983  typename std::iterator_traits<InputIterator>::value_type& max_value)
3984  {
3985  min_value = *begin;
3986  max_value = *begin;
3987  InputIterator itr = begin;
3988  while (end != ++itr)
3989  {
3990  if (*itr < min_value)
3991  min_value = (*itr);
3992  else if (*itr > max_value)
3993  max_value = (*itr);
3994  }
3995  }
3996 
3997  template <typename T,
3998  typename Allocator,
3999  template <typename,typename> class Sequence>
4000  inline void min_max_of_cont(const Sequence<T,Allocator>& sequence,
4001  T& min_value,
4002  T& max_value)
4003  {
4004  min_max_of_range(sequence.begin(),sequence.end(),
4005  min_value,
4006  max_value);
4007  }
4008 
4009  template <typename T,
4010  typename Comparator,
4011  typename Allocator>
4012  inline void min_max_of_cont(const std::set<T,Comparator,Allocator>& set,
4013  T& min_value,
4014  T& max_value)
4015  {
4016  min_value = (*set.begin());
4017  max_value = (*set.rbegin());
4018  }
4019 
4020  template <typename T,
4021  typename Comparator,
4022  typename Allocator>
4023  inline void min_max_of_cont(const std::multiset<T,Comparator,Allocator>& multiset,
4024  T& min_value,
4025  T& max_value)
4026  {
4027  min_value = (*multiset.begin());
4028  max_value = (*multiset.rbegin());
4029  }
4030 
4031  template <typename Iterator>
4032  inline void lexicographically_canonicalize(Iterator begin, Iterator end)
4033  {
4034  typedef typename std::iterator_traits<Iterator>::value_type type;
4035  typedef typename std::pair<Iterator,Iterator> iter_type;
4036  typedef typename std::list<iter_type> itr_list_type;
4037  itr_list_type itr_list;
4038 
4039  type smallest = (*std::min_element(begin,end));
4040 
4041  for (Iterator itr = begin; itr != end; ++itr)
4042  {
4043  if (*itr == smallest) itr_list.push_back(std::make_pair(itr,itr));
4044  }
4045 
4046  while (itr_list.size() > 1)
4047  {
4048  typename itr_list_type::iterator itr = itr_list.begin();
4049  while (itr_list.end() != itr)
4050  {
4051  ++(*itr).first;
4052  if (end == (*itr).first)
4053  itr = itr_list.erase(itr);
4054  else
4055  ++itr;
4056  }
4057 
4058  smallest = *(*itr_list.begin()).first;
4059 
4060  for (itr = (++itr_list.begin()); itr != itr_list.end(); ++itr)
4061  {
4062  if (*(*itr).first < smallest)
4063  {
4064  smallest = *(*itr).first;
4065  }
4066  }
4067 
4068  itr = itr_list.begin();
4069  while (itr_list.end() != itr)
4070  {
4071  if (*(*itr).first != smallest)
4072  itr = itr_list.erase(itr);
4073  else
4074  ++itr;
4075  }
4076 
4077  itr = itr_list.begin();
4078  while (itr_list.end() != itr)
4079  {
4080  if (end == (*itr).first)
4081  itr = itr_list.erase(itr);
4082  else
4083  ++itr;
4084  }
4085 
4086  }
4087 
4088  std::rotate(begin,(*itr_list.begin()).second,end);
4089  }
4090 
4092  {
4093  lexicographically_canonicalize(const_cast<char*>(str.data()),
4094  const_cast<char*>(str.data() + str.size()));
4095  }
4096 
4097  template <typename T,
4098  typename Allocator,
4099  template <typename,typename> class Sequence>
4100  inline void lexicographically_canonicalize(Sequence<T,Allocator>& sequence)
4101  {
4102  lexicographically_canonicalize(sequence.begin(),sequence.end());
4103  }
4104 
4105  inline const char* first_non_repeated_char(const char* begin, const char* end)
4106  {
4107  static const std::size_t lut_size = 256;
4108  unsigned long long int lut[lut_size];
4109 
4110  std::fill_n(lut,lut_size,std::numeric_limits<unsigned long long int>::max());
4111 
4112  static const unsigned long long int not_yet_encountered = std::numeric_limits<unsigned long long int>::max();
4113  static const unsigned long long int repeated = not_yet_encountered - 1;
4114 
4115  const char* itr = begin;
4116  unsigned long long int position = 0;
4117  while (end != itr)
4118  {
4119  unsigned long long int& element = lut[static_cast<unsigned int>(*itr)];
4120  if (not_yet_encountered == element)
4121  {
4122  element = position;
4123  }
4124  else if (element < repeated)
4125  {
4126  element = repeated;
4127  }
4128  ++itr;
4129  ++position;
4130  }
4131 
4132  position = repeated;
4133 
4134  for (std::size_t i = 0; i < lut_size; ++i)
4135  {
4136  if (lut[i] < position)
4137  position = lut[i];
4138  }
4139 
4140  return (repeated != position) ? (begin + position) : end;
4141  }
4142 
4143  inline const unsigned char* first_non_repeated_char(const unsigned char* begin, const unsigned char* end)
4144  {
4145  char * b = reinterpret_cast<char*>(const_cast<unsigned char*>(begin));
4146  char * e = reinterpret_cast<char*>(const_cast<unsigned char*>(end));
4147  return const_cast<const unsigned char*>(reinterpret_cast<unsigned char*>(const_cast<char*>(first_non_repeated_char(b,e))));
4148  }
4149 
4150  inline std::size_t first_non_repeated_char(const std::string& str)
4151  {
4152  if (str.empty())
4153  return static_cast<std::size_t>(std::string::npos);
4154  const char* itr = first_non_repeated_char(str.data(),str.data() + str.size());
4155  if ((str.data() + str.size()) != itr)
4156  return static_cast<std::size_t>(itr - str.data());
4157  else
4158  return static_cast<std::size_t>(std::string::npos);
4159  }
4160 
4161  inline void convert_bin_to_hex(const unsigned char* begin, const unsigned char* end, unsigned char* out)
4162  {
4163  static const unsigned short hex_lut[] =
4164  {
4165  0x3030, 0x3130, 0x3230, 0x3330, 0x3430, 0x3530, 0x3630, 0x3730,
4166  0x3830, 0x3930, 0x4130, 0x4230, 0x4330, 0x4430, 0x4530, 0x4630,
4167  0x3031, 0x3131, 0x3231, 0x3331, 0x3431, 0x3531, 0x3631, 0x3731,
4168  0x3831, 0x3931, 0x4131, 0x4231, 0x4331, 0x4431, 0x4531, 0x4631,
4169  0x3032, 0x3132, 0x3232, 0x3332, 0x3432, 0x3532, 0x3632, 0x3732,
4170  0x3832, 0x3932, 0x4132, 0x4232, 0x4332, 0x4432, 0x4532, 0x4632,
4171  0x3033, 0x3133, 0x3233, 0x3333, 0x3433, 0x3533, 0x3633, 0x3733,
4172  0x3833, 0x3933, 0x4133, 0x4233, 0x4333, 0x4433, 0x4533, 0x4633,
4173  0x3034, 0x3134, 0x3234, 0x3334, 0x3434, 0x3534, 0x3634, 0x3734,
4174  0x3834, 0x3934, 0x4134, 0x4234, 0x4334, 0x4434, 0x4534, 0x4634,
4175  0x3035, 0x3135, 0x3235, 0x3335, 0x3435, 0x3535, 0x3635, 0x3735,
4176  0x3835, 0x3935, 0x4135, 0x4235, 0x4335, 0x4435, 0x4535, 0x4635,
4177  0x3036, 0x3136, 0x3236, 0x3336, 0x3436, 0x3536, 0x3636, 0x3736,
4178  0x3836, 0x3936, 0x4136, 0x4236, 0x4336, 0x4436, 0x4536, 0x4636,
4179  0x3037, 0x3137, 0x3237, 0x3337, 0x3437, 0x3537, 0x3637, 0x3737,
4180  0x3837, 0x3937, 0x4137, 0x4237, 0x4337, 0x4437, 0x4537, 0x4637,
4181  0x3038, 0x3138, 0x3238, 0x3338, 0x3438, 0x3538, 0x3638, 0x3738,
4182  0x3838, 0x3938, 0x4138, 0x4238, 0x4338, 0x4438, 0x4538, 0x4638,
4183  0x3039, 0x3139, 0x3239, 0x3339, 0x3439, 0x3539, 0x3639, 0x3739,
4184  0x3839, 0x3939, 0x4139, 0x4239, 0x4339, 0x4439, 0x4539, 0x4639,
4185  0x3041, 0x3141, 0x3241, 0x3341, 0x3441, 0x3541, 0x3641, 0x3741,
4186  0x3841, 0x3941, 0x4141, 0x4241, 0x4341, 0x4441, 0x4541, 0x4641,
4187  0x3042, 0x3142, 0x3242, 0x3342, 0x3442, 0x3542, 0x3642, 0x3742,
4188  0x3842, 0x3942, 0x4142, 0x4242, 0x4342, 0x4442, 0x4542, 0x4642,
4189  0x3043, 0x3143, 0x3243, 0x3343, 0x3443, 0x3543, 0x3643, 0x3743,
4190  0x3843, 0x3943, 0x4143, 0x4243, 0x4343, 0x4443, 0x4543, 0x4643,
4191  0x3044, 0x3144, 0x3244, 0x3344, 0x3444, 0x3544, 0x3644, 0x3744,
4192  0x3844, 0x3944, 0x4144, 0x4244, 0x4344, 0x4444, 0x4544, 0x4644,
4193  0x3045, 0x3145, 0x3245, 0x3345, 0x3445, 0x3545, 0x3645, 0x3745,
4194  0x3845, 0x3945, 0x4145, 0x4245, 0x4345, 0x4445, 0x4545, 0x4645,
4195  0x3046, 0x3146, 0x3246, 0x3346, 0x3446, 0x3546, 0x3646, 0x3746,
4196  0x3846, 0x3946, 0x4146, 0x4246, 0x4346, 0x4446, 0x4546, 0x4646
4197  };
4198 
4199  for (const unsigned char* itr = begin; end != itr; ++itr)
4200  {
4201  *reinterpret_cast<unsigned short*>(out) = hex_lut[(*itr)];
4202  out += sizeof(unsigned short);
4203  }
4204  }
4205 
4206  inline void convert_bin_to_hex(const char* begin, const char* end, char* out)
4207  {
4208  convert_bin_to_hex(reinterpret_cast<const unsigned char*>(begin),
4209  reinterpret_cast<const unsigned char*>(end),
4210  reinterpret_cast<unsigned char*>(out));
4211  }
4212 
4213  inline void convert_bin_to_hex(const std::pair<unsigned char*,unsigned char*>& r, unsigned char* out)
4214  {
4215  convert_bin_to_hex(r.first,r.second,out);
4216  }
4217 
4218  inline void convert_bin_to_hex(const std::pair<const unsigned char*,const unsigned char*>& r, unsigned char* out)
4219  {
4220  convert_bin_to_hex(r.first,r.second,out);
4221  }
4222 
4223  inline void convert_bin_to_hex(const std::pair<const char*,const char*>& r, char* out)
4224  {
4225  convert_bin_to_hex(r.first,r.second,out);
4226  }
4227 
4228  inline void convert_bin_to_hex(const std::string& binary_data, std::string& output)
4229  {
4230  output.resize(binary_data.size() * 2);
4231  convert_bin_to_hex(binary_data.data(),
4232  binary_data.data() + binary_data.size(),
4233  const_cast<char*>(output.data()));
4234  }
4235 
4236  inline std::string convert_bin_to_hex(const std::string& binary_data)
4237  {
4238  std::string output;
4239  convert_bin_to_hex(binary_data,output);
4240  return output;
4241  }
4242 
4243  inline bool convert_hex_to_bin(const unsigned char* begin, const unsigned char* end, unsigned char* out)
4244  {
4245  const std::size_t length = std::distance(begin,end);
4246  if (0 == length)
4247  return false;
4248  else if (1 == (length % 2))
4249  return false;
4250  static const unsigned char hex_to_bin[] =
4251  {
4252  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x00 - 0x07
4253  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x08 - 0x0F
4254  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x10 - 0x17
4255  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x18 - 0x1F
4256  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x20 - 0x27
4257  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x28 - 0x2F
4258  0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, // 0x30 - 0x37
4259  0x08, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x38 - 0x3F
4260  0x00, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x00, // 0x40 - 0x47
4261  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x48 - 0x4F
4262  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x50 - 0x57
4263  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x58 - 0x5F
4264  0x00, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x00, // 0x60 - 0x67
4265  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x68 - 0x6F
4266  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x70 - 0x77
4267  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x78 - 0x7F
4268  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x80 - 0x87
4269  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x88 - 0x8F
4270  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x90 - 0x97
4271  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x98 - 0x9F
4272  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xA0 - 0xA7
4273  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xA8 - 0xAF
4274  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xB0 - 0xB7
4275  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xB8 - 0xBF
4276  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xC0 - 0xC7
4277  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xC8 - 0xCF
4278  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xD0 - 0xD7
4279  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xD8 - 0xDF
4280  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xE0 - 0xE7
4281  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xE8 - 0xEF
4282  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xF0 - 0xF7
4283  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // 0xF8 - 0xFF
4284  };
4285 
4286  const unsigned char* itr = begin;
4287  while (end != itr)
4288  {
4289  *reinterpret_cast<unsigned char*>(out) = static_cast<unsigned char>(hex_to_bin[itr[0]] << 4 | hex_to_bin[itr[1]]);
4290  ++out;
4291  itr += 2;
4292  }
4293  return true;
4294  }
4295 
4296  inline bool convert_hex_to_bin(const char* begin, const char* end, char* out)
4297  {
4298  return convert_hex_to_bin(reinterpret_cast<const unsigned char*>(begin),
4299  reinterpret_cast<const unsigned char*>(end),
4300  reinterpret_cast<unsigned char*>(out));
4301  }
4302 
4303  inline bool convert_hex_to_bin(const std::pair<unsigned char*,unsigned char*>& r, unsigned char* out)
4304  {
4305  return convert_hex_to_bin(r.first,r.second,out);
4306  }
4307 
4308  inline bool convert_hex_to_bin(const std::pair<const unsigned char*,const unsigned char*>& r, unsigned char* out)
4309  {
4310  return convert_hex_to_bin(r.first,r.second,out);
4311  }
4312 
4313  inline bool convert_hex_to_bin(const std::pair<char*,char*>& r, char* out)
4314  {
4315  return convert_hex_to_bin(r.first,r.second,out);
4316  }
4317 
4318  inline bool convert_hex_to_bin(const std::pair<const char*,const char*>& r, char* out)
4319  {
4320  return convert_hex_to_bin(r.first,r.second,out);
4321  }
4322 
4323  inline bool convert_hex_to_bin(const std::string& hex_data, std::string& output)
4324  {
4325  if (hex_data.empty() || (1 == (hex_data.size() % 2)))
4326  return false;
4327  output.resize(hex_data.size() >> 1);
4328  return convert_hex_to_bin(hex_data.data(),
4329  hex_data.data() + hex_data.size(),
4330  const_cast<char*>(output.data()));
4331  }
4332 
4333  inline std::size_t convert_bin_to_base64(const unsigned char* begin, const unsigned char* end, unsigned char* out)
4334  {
4335  static const unsigned char bin_to_base64 [] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
4336 
4337  const std::size_t length = std::distance(begin,end);
4338  std::size_t rounds = length / 3;
4339  const unsigned char* itr = begin;
4340  for (std::size_t i = 0; i < rounds; ++i)
4341  {
4342  unsigned int block = *(itr++) << 16;
4343  block |= *(itr++) << 8;
4344  block |= *(itr++) ;
4345  *(out++) = bin_to_base64[( block >> 18 ) & 0x3F];
4346  *(out++) = bin_to_base64[( block >> 12 ) & 0x3F];
4347  *(out++) = bin_to_base64[( block >> 6 ) & 0x3F];
4348  *(out++) = bin_to_base64[( block ) & 0x3F];
4349  }
4350 
4351  if ((rounds = (length % 3)) > 0)
4352  {
4353  switch (rounds)
4354  {
4355  case 1 : {
4356  unsigned int block = (unsigned char) (*itr) << 16;
4357  *(out++) = bin_to_base64[( block >> 18 ) & 0x3F];
4358  *(out++) = bin_to_base64[( block >> 12 ) & 0x3F];
4359  *(out++) = '=';
4360  *(out++) = '=';
4361  }
4362  break;
4363 
4364  case 2 : {
4365  unsigned int block = *(itr++) << 16;
4366  block |= *(itr++) << 8;
4367  *(out++) = bin_to_base64[( block >> 18 ) & 0x3F];
4368  *(out++) = bin_to_base64[( block >> 12 ) & 0x3F];
4369  *(out++) = bin_to_base64[( block >> 6 ) & 0x3F];
4370  *(out++) = '=';
4371  }
4372  break;
4373  }
4374  }
4375  return static_cast<std::size_t>((length / 3) * 4) + ((length % 3) > 0 ? 4 : 0);
4376  }
4377 
4378  inline std::size_t convert_bin_to_base64(const char* begin, const char* end, char* out)
4379  {
4380  return convert_bin_to_base64(reinterpret_cast<const unsigned char*>(begin),
4381  reinterpret_cast<const unsigned char*>(end),
4382  reinterpret_cast<unsigned char*>(out));
4383  }
4384 
4385  inline void convert_bin_to_base64(const std::string& binary_data, std::string& output)
4386  {
4387  output.resize(std::max<std::size_t>(4,binary_data.size() << 1));
4388  std::size_t resize = convert_bin_to_base64(binary_data.data(),
4389  binary_data.data() + binary_data.size(),
4390  const_cast<char*>(output.data()));
4391  output.resize(resize);
4392  }
4393 
4394  inline std::size_t convert_base64_to_bin(const unsigned char* begin, const unsigned char* end, unsigned char* out)
4395  {
4396  static const unsigned char base64_to_bin[] =
4397  {
4398  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x00 - 0x07
4399  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x08 - 0x0F
4400  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x10 - 0x17
4401  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x18 - 0x1F
4402  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x20 - 0x27
4403  0xFF, 0xFF, 0xFF, 0x3E, 0xFF, 0xFF, 0xFF, 0x3F, // 0x28 - 0x2F
4404  0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, // 0x30 - 0x37
4405  0x3C, 0x3D, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x38 - 0x3F
4406  0xFF, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, // 0x40 - 0x47
4407  0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, // 0x48 - 0x4F
4408  0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, // 0x50 - 0x57
4409  0x17, 0x18, 0x19, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x58 - 0x5F
4410  0xFF, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, // 0x60 - 0x67
4411  0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, // 0x68 - 0x6F
4412  0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, // 0x70 - 0x77
4413  0x31, 0x32, 0x33, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x78 - 0x7F
4414  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x80 - 0x87
4415  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x88 - 0x8F
4416  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x90 - 0x97
4417  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x98 - 0x9F
4418  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0xA0 - 0xA7
4419  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0xA8 - 0xAF
4420  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0xB0 - 0xB7
4421  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0xB8 - 0xBF
4422  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0xC0 - 0xC7
4423  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0xC8 - 0xCF
4424  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0xD0 - 0xD7
4425  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0xD8 - 0xDF
4426  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0xE0 - 0xE7
4427  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0xE8 - 0xEF
4428  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0xF0 - 0xF7
4429  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF // 0xF8 - 0xFF
4430  };
4431 
4432  const unsigned char* end_itr = end;
4433 
4434  if ('=' == *(end - 2))
4435  end_itr = end - 2;
4436  else if ('=' == *(end - 1))
4437  end_itr = end - 1;
4438 
4439  const std::size_t length = std::distance(begin,end_itr);
4440  const std::size_t rounds = length / 4;
4441  const unsigned char* itr = begin;
4442 
4443  for (std::size_t i = 0; i < rounds; ++i)
4444  {
4445  unsigned int block = base64_to_bin[*(itr++)] << 18;
4446  block |= base64_to_bin[*(itr++)] << 12;
4447  block |= base64_to_bin[*(itr++)] << 6;
4448  block |= base64_to_bin[*(itr++)];
4449 
4450  *(out++) = static_cast<unsigned char>(( block >> 16 ) & 0xFF);
4451  *(out++) = static_cast<unsigned char>(( block >> 8 ) & 0xFF);
4452  *(out++) = static_cast<unsigned char>(( block ) & 0xFF);
4453  }
4454 
4455  const std::size_t remainder = (length % 4);
4456  if (remainder > 0)
4457  {
4458  switch (remainder)
4459  {
4460  case 2 : {
4461  unsigned int block = base64_to_bin[*(itr++)] << 18;
4462  block |= base64_to_bin[*(itr++)] << 12;
4463  (*out) = static_cast<unsigned char>(( block >> 16 ) & 0xFF);
4464  }
4465  break;
4466 
4467  case 3 : {
4468  unsigned int block = base64_to_bin[*(itr++)] << 18;
4469  block |= base64_to_bin[*(itr++)] << 12;
4470  block |= base64_to_bin[*(itr++)] << 6;
4471  *(out++) = static_cast<unsigned char>(( block >> 16 ) & 0xFF);
4472  *(out ) = static_cast<unsigned char>(( block >> 8 ) & 0xFF);
4473  }
4474  break;
4475  }
4476  }
4477 
4478  return static_cast<std::size_t>((3 * length) / 4);
4479  }
4480 
4481  inline std::size_t convert_base64_to_bin(const char* begin, const char* end, char* out)
4482  {
4483  return convert_base64_to_bin(reinterpret_cast<const unsigned char*>(begin),
4484  reinterpret_cast<const unsigned char*>(end),
4485  reinterpret_cast<unsigned char*>(out));
4486  }
4487 
4488  inline void convert_base64_to_bin(const std::string& binary_data, std::string& output)
4489  {
4490  output.resize(binary_data.size());
4491  std::size_t resize = convert_base64_to_bin(binary_data.data(),
4492  binary_data.data() + binary_data.size(),
4493  const_cast<char*>(output.data()));
4494  output.resize(resize);
4495  }
4496 
4497  inline void convert_to_printable_chars(unsigned char* begin, unsigned char* end)
4498  {
4499  static const unsigned char printable_char_table[] =
4500  {
4501  0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, // 0x00 - 0x07
4502  0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, // 0x08 - 0x0F
4503  0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, // 0x10 - 0x17
4504  0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, // 0x18 - 0x1F
4505  0x2E, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, // 0x20 - 0x27
4506  0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, // 0x28 - 0x2F
4507  0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, // 0x30 - 0x37
4508  0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, // 0x38 - 0x3F
4509  0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, // 0x40 - 0x47
4510  0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, // 0x48 - 0x4F
4511  0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, // 0x50 - 0x57
4512  0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, // 0x58 - 0x5F
4513  0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, // 0x60 - 0x67
4514  0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, // 0x68 - 0x6F
4515  0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, // 0x70 - 0x77
4516  0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x2E, // 0x78 - 0x7F
4517  0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, // 0x80 - 0x87
4518  0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, // 0x88 - 0x8F
4519  0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, // 0x90 - 0x97
4520  0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, // 0x98 - 0x9F
4521  0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, // 0xA0 - 0xA7
4522  0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, // 0xA8 - 0xAF
4523  0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, // 0xB0 - 0xB7
4524  0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, // 0xB8 - 0xBF
4525  0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, // 0xC0 - 0xC7
4526  0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, // 0xC8 - 0xCF
4527  0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, // 0xD0 - 0xD7
4528  0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, // 0xD8 - 0xDF
4529  0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, // 0xE0 - 0xE7
4530  0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, // 0xE8 - 0xEF
4531  0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, // 0xF0 - 0xF7
4532  0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E // 0xF8 - 0xFF
4533  };
4534  unsigned char* itr = begin;
4535  while (end != itr)
4536  {
4537  (*itr) = printable_char_table[static_cast<unsigned int>((*itr))];
4538  ++itr;
4539  }
4540  }
4541 
4542  inline void convert_to_printable_chars(char* begin, char* end)
4543  {
4544  convert_to_printable_chars(reinterpret_cast<unsigned char*>(begin),
4545  reinterpret_cast<unsigned char*>(end));
4546  }
4547 
4549  {
4550  convert_to_printable_chars(reinterpret_cast<unsigned char*>(const_cast<char*>(str.data())),
4551  reinterpret_cast<unsigned char*>(const_cast<char*>(str.data() + str.size())));
4552  }
4553 
4554  inline void convert_to_uppercase(unsigned char* begin, unsigned char* end)
4555  {
4556  std::transform(begin,end,begin,::toupper);
4557  /*
4558  unsigned char* itr = begin;
4559  while (end != itr)
4560  {
4561  //(*itr) = std::toupper((*itr), std::locale::classic());
4562  (*itr) = static_cast<unsigned char>(::toupper(static_cast<int>(*itr)));
4563  ++itr;
4564  }
4565  */
4566  }
4567 
4568  inline void convert_to_uppercase(char* begin, char* end)
4569  {
4570  convert_to_uppercase(reinterpret_cast<unsigned char*>(begin),
4571  reinterpret_cast<unsigned char*>(end));
4572  }
4573 
4575  {
4576  convert_to_uppercase(reinterpret_cast<unsigned char*>(const_cast<char*>(str.data())),
4577  reinterpret_cast<unsigned char*>(const_cast<char*>(str.data() + str.size())));
4578  }
4579 
4580  inline void convert_to_lowercase(unsigned char* begin, unsigned char* end)
4581  {
4582  std::transform(begin,end,begin,::tolower);
4583  /*
4584  unsigned char* itr = begin;
4585  while (end != itr)
4586  {
4587  //(*itr) = std::tolower((*itr), std::locale::classic());
4588  (*itr) = static_cast<unsigned char>(::tolower(static_cast<int>(*itr)));
4589  ++itr;
4590  }
4591  */
4592  }
4593 
4594  inline void convert_to_lowercase(char* begin, char* end)
4595  {
4596  convert_to_lowercase(reinterpret_cast<unsigned char*>(begin),
4597  reinterpret_cast<unsigned char*>(end));
4598  }
4599 
4600  inline void convert_to_lowercase(const char* begin, const char* end)
4601  {
4602  convert_to_lowercase(const_cast<char*>(begin),const_cast<char*>(end));
4603  }
4604 
4606  {
4607  convert_to_lowercase(reinterpret_cast<unsigned char*>(const_cast<char*>(str.data())),
4608  reinterpret_cast<unsigned char*>(const_cast<char*>(str.data() + str.size())));
4609  }
4610 
4612  {
4613  std::string result = str;
4614  convert_to_lowercase(result);
4615  return result;
4616  }
4617 
4619  {
4620  std::string result = str;
4621  convert_to_uppercase(result);
4622  return result;
4623  }
4624 
4625  inline bool twoway_bitwise_interleave(const unsigned char* begin1, const unsigned char* end1,
4626  const unsigned char* begin2, const unsigned char* end2,
4627  unsigned char* out)
4628  {
4629  if (std::distance(begin1,end1) != std::distance(begin2,end2))
4630  {
4631  return false;
4632  }
4633 
4634  static const std::size_t interleave_table_size = 256;
4635  static const unsigned short interleave_table[interleave_table_size] =
4636  {
4637  0x0000, 0x0001, 0x0004, 0x0005, 0x0010, 0x0011, 0x0014, 0x0015, // 0x00 - 0x07
4638  0x0040, 0x0041, 0x0044, 0x0045, 0x0050, 0x0051, 0x0054, 0x0055, // 0x08 - 0x0F
4639  0x0100, 0x0101, 0x0104, 0x0105, 0x0110, 0x0111, 0x0114, 0x0115, // 0x10 - 0x17
4640  0x0140, 0x0141, 0x0144, 0x0145, 0x0150, 0x0151, 0x0154, 0x0155, // 0x18 - 0x1F
4641  0x0400, 0x0401, 0x0404, 0x0405, 0x0410, 0x0411, 0x0414, 0x0415, // 0x20 - 0x27
4642  0x0440, 0x0441, 0x0444, 0x0445, 0x0450, 0x0451, 0x0454, 0x0455, // 0x28 - 0x2F
4643  0x0500, 0x0501, 0x0504, 0x0505, 0x0510, 0x0511, 0x0514, 0x0515, // 0x30 - 0x37
4644  0x0540, 0x0541, 0x0544, 0x0545, 0x0550, 0x0551, 0x0554, 0x0555, // 0x38 - 0x3F
4645  0x1000, 0x1001, 0x1004, 0x1005, 0x1010, 0x1011, 0x1014, 0x1015, // 0x40 - 0x47
4646  0x1040, 0x1041, 0x1044, 0x1045, 0x1050, 0x1051, 0x1054, 0x1055, // 0x48 - 0x4F
4647  0x1100, 0x1101, 0x1104, 0x1105, 0x1110, 0x1111, 0x1114, 0x1115, // 0x50 - 0x57
4648  0x1140, 0x1141, 0x1144, 0x1145, 0x1150, 0x1151, 0x1154, 0x1155, // 0x58 - 0x5F
4649  0x1400, 0x1401, 0x1404, 0x1405, 0x1410, 0x1411, 0x1414, 0x1415, // 0x60 - 0x67
4650  0x1440, 0x1441, 0x1444, 0x1445, 0x1450, 0x1451, 0x1454, 0x1455, // 0x68 - 0x6F
4651  0x1500, 0x1501, 0x1504, 0x1505, 0x1510, 0x1511, 0x1514, 0x1515, // 0x70 - 0x77
4652  0x1540, 0x1541, 0x1544, 0x1545, 0x1550, 0x1551, 0x1554, 0x1555, // 0x78 - 0x7F
4653  0x4000, 0x4001, 0x4004, 0x4005, 0x4010, 0x4011, 0x4014, 0x4015, // 0x80 - 0x87
4654  0x4040, 0x4041, 0x4044, 0x4045, 0x4050, 0x4051, 0x4054, 0x4055, // 0x88 - 0x8F
4655  0x4100, 0x4101, 0x4104, 0x4105, 0x4110, 0x4111, 0x4114, 0x4115, // 0x90 - 0x97
4656  0x4140, 0x4141, 0x4144, 0x4145, 0x4150, 0x4151, 0x4154, 0x4155, // 0x98 - 0x9F
4657  0x4400, 0x4401, 0x4404, 0x4405, 0x4410, 0x4411, 0x4414, 0x4415, // 0xA0 - 0xA7
4658  0x4440, 0x4441, 0x4444, 0x4445, 0x4450, 0x4451, 0x4454, 0x4455, // 0xA8 - 0xAF
4659  0x4500, 0x4501, 0x4504, 0x4505, 0x4510, 0x4511, 0x4514, 0x4515, // 0xB0 - 0xB7
4660  0x4540, 0x4541, 0x4544, 0x4545, 0x4550, 0x4551, 0x4554, 0x4555, // 0xB8 - 0xBF
4661  0x5000, 0x5001, 0x5004, 0x5005, 0x5010, 0x5011, 0x5014, 0x5015, // 0xC0 - 0xC7
4662  0x5040, 0x5041, 0x5044, 0x5045, 0x5050, 0x5051, 0x5054, 0x5055, // 0xC8 - 0xCF
4663  0x5100, 0x5101, 0x5104, 0x5105, 0x5110, 0x5111, 0x5114, 0x5115, // 0xD0 - 0xD7
4664  0x5140, 0x5141, 0x5144, 0x5145, 0x5150, 0x5151, 0x5154, 0x5155, // 0xD8 - 0xDF
4665  0x5400, 0x5401, 0x5404, 0x5405, 0x5410, 0x5411, 0x5414, 0x5415, // 0xE0 - 0xE7
4666  0x5440, 0x5441, 0x5444, 0x5445, 0x5450, 0x5451, 0x5454, 0x5455, // 0xE8 - 0xEF
4667  0x5500, 0x5501, 0x5504, 0x5505, 0x5510, 0x5511, 0x5514, 0x5515, // 0xF0 - 0xF7
4668  0x5540, 0x5541, 0x5544, 0x5545, 0x5550, 0x5551, 0x5554, 0x5555 // 0xF8 - 0xFF
4669  };
4670 
4671  const unsigned char* itr1 = begin1;
4672  const unsigned char* itr2 = begin2;
4673  while (end1 != itr1)
4674  {
4675  *(reinterpret_cast<unsigned short*>(out)) = (interleave_table[*(itr2++)] << 1);
4676  *(reinterpret_cast<unsigned short*>(out)) |= interleave_table[*(itr1++)];
4677  out += 2;
4678  }
4679  return true;
4680  }
4681 
4682  inline bool twoway_bitwise_interleave(const char* begin1, const char* end1,
4683  const char* begin2, const char* end2,
4684  char* out)
4685  {
4686  return twoway_bitwise_interleave(reinterpret_cast<const unsigned char*>(begin1),
4687  reinterpret_cast<const unsigned char*>(end1),
4688  reinterpret_cast<const unsigned char*>(begin2),
4689  reinterpret_cast<const unsigned char*>(end2),
4690  reinterpret_cast<unsigned char*>(out));
4691  }
4692 
4693  inline bool twoway_bitwise_interleave(const std::string& str1,
4694  const std::string& str2,
4695  std::string& out)
4696  {
4697  if (str1.size() != str2.size())
4698  {
4699  return false;
4700  }
4701  out.resize(str1.size());
4702  return twoway_bitwise_interleave(str1.data(),str1.data() + str1.size(),
4703  str2.data(),str2.data() + str2.size(),
4704  const_cast<char*>(out.data()));
4705  }
4706 
4707  template <std::size_t n>
4709 
4710  template<> struct interleave_ary<sizeof(unsigned short)> { typedef unsigned short type; };
4711  template<> struct interleave_ary<sizeof(unsigned int )> { typedef unsigned int type; };
4712  template<> struct interleave_ary<sizeof(unsigned long long int)> { typedef unsigned long long int type; };
4713 
4714  template <std::size_t n>
4716  {
4717  typedef typename interleave_ary<n>::type type;
4718  const type diff = static_cast<type>(n - 1);
4719  for (type i = static_cast<type>(0); i < static_cast<type>(256); ++i)
4720  {
4721  table[i] = 0x00;
4722  for (type j = static_cast<type>(0); j < static_cast<type>(8); ++j)
4723  {
4724  table[i] |= (i & (1 << j)) << (j * diff);
4725  }
4726  }
4727  }
4728 
4729  namespace bitwise_operation { enum type { eAND, eOR, eXOR }; }
4730 
4731  inline void bitwise_transform(const bitwise_operation::type& operation,
4732  const unsigned char* begin1, const unsigned char* end1,
4733  const unsigned char* begin2,
4734  unsigned char* out)
4735  {
4736  const unsigned char* itr1 = begin1;
4737  const unsigned char* itr2 = begin2;
4738 
4739  switch (operation)
4740  {
4741  case bitwise_operation::eAND : while (itr1 != end1) { *(out++) = *(itr1++) & *(itr2++); } return;
4742  case bitwise_operation::eOR : while (itr1 != end1) { *(out++) = *(itr1++) | *(itr2++); } return;
4743  case bitwise_operation::eXOR : while (itr1 != end1) { *(out++) = *(itr1++) ^ *(itr2++); } return;
4744  }
4745  }
4746 
4747  inline void bitwise_transform(const bitwise_operation::type& operation,
4748  const char* begin1, const char* end1,
4749  const char* begin2,
4750  char* out)
4751  {
4752  bitwise_transform(operation,
4753  reinterpret_cast<const unsigned char*>(begin1),
4754  reinterpret_cast<const unsigned char*>(end1),
4755  reinterpret_cast<const unsigned char*>(begin2),
4756  reinterpret_cast<unsigned char*>(out));
4757  }
4758 
4759  inline void bitwise_transform(const bitwise_operation::type& operation,
4760  const std::string& str1,
4761  const std::string& str2,
4762  std::string& out)
4763  {
4764  if (str1.size() != str2.size()) return;
4765  out.resize(str1.size());
4766  bitwise_transform(operation,
4767  str1.data(),str1.data() + str1.size(),
4768  str2.data(),
4769  const_cast<char*>(out.data()));
4770  }
4771 
4772  inline std::size_t high_bit_count(const unsigned char c)
4773  {
4774  static const std::size_t high_bits_in_char[256] =
4775  {
4776  0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,
4777  1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
4778  1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
4779  2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
4780  1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
4781  2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
4782  2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
4783  3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
4784  1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
4785  2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
4786  2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
4787  3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
4788  2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
4789  3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
4790  3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
4791  4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8
4792  };
4793  return high_bits_in_char[c];
4794  }
4795 
4796  inline std::size_t high_bit_count(const unsigned short& s)
4797  {
4798  const unsigned char* ptr = reinterpret_cast<const unsigned char*>(&s);
4799  return high_bit_count(*(ptr + 0)) + high_bit_count(*(ptr + 1));
4800  }
4801 
4802  inline std::size_t high_bit_count(const unsigned int& i)
4803  {
4804  const unsigned char* ptr = reinterpret_cast<const unsigned char*>(&i);
4805  return high_bit_count(*(ptr + 0)) + high_bit_count(*(ptr + 1)) +
4806  high_bit_count(*(ptr + 2)) + high_bit_count(*(ptr + 3));
4807  }
4808 
4809  inline std::size_t high_bit_count(const long long int& ll)
4810  {
4811  const unsigned char* ptr = reinterpret_cast<const unsigned char*>(&ll);
4812  return high_bit_count(*(ptr + 0)) + high_bit_count(*(ptr + 1)) +
4813  high_bit_count(*(ptr + 2)) + high_bit_count(*(ptr + 3)) +
4814  high_bit_count(*(ptr + 4)) + high_bit_count(*(ptr + 5)) +
4815  high_bit_count(*(ptr + 6)) + high_bit_count(*(ptr + 7));
4816  }
4817 
4818  inline std::size_t high_bit_count(const unsigned char* begin, const unsigned char* end)
4819  {
4820  std::size_t count = 0;
4821  const unsigned char* itr = begin;
4822  while (end != itr)
4823  {
4824  count += high_bit_count(*itr++);
4825  }
4826  return count;
4827  }
4828 
4829  inline std::size_t high_bit_count(const char* begin, const char* end)
4830  {
4831  return high_bit_count(reinterpret_cast<const unsigned char*>(begin),
4832  reinterpret_cast<const unsigned char*>(end));
4833 
4834  }
4835 
4836  inline std::size_t high_bit_count(const std::string& str)
4837  {
4838  return high_bit_count(str.data(),str.data() + str.size());
4839  }
4840 
4841  inline bool bit_state(const std::size_t& index, const unsigned char* ptr)
4842  {
4843  static const unsigned char bit_mask[] =
4844  {
4845  0x01, //00000001
4846  0x02, //00000010
4847  0x04, //00000100
4848  0x08, //00001000
4849  0x10, //00010000
4850  0x20, //00100000
4851  0x40, //01000000
4852  0x80 //10000000
4853  };
4854  return (0 != (ptr[(index >> 3)] & bit_mask[index & 7]));
4855  }
4856 
4857  inline void set_bit_high(const std::size_t& index, unsigned char* const ptr)
4858  {
4859  static const unsigned char bit_mask[] =
4860  {
4861  0x01, //00000001
4862  0x02, //00000010
4863  0x04, //00000100
4864  0x08, //00001000
4865  0x10, //00010000
4866  0x20, //00100000
4867  0x40, //01000000
4868  0x80 //10000000
4869  };
4870  ptr[(index >> 3)] |= bit_mask[index & 7];
4871  }
4872 
4873  inline void set_bit_low(const std::size_t& index, unsigned char* const ptr)
4874  {
4875  static const unsigned char bit_mask[] =
4876  {
4877  0xFE, //11111110
4878  0xFD, //11111101
4879  0xFB, //11111011
4880  0xF7, //11110111
4881  0xEF, //11101111
4882  0xDF, //11011111
4883  0xBF, //10111111
4884  0x7F //01111111
4885  };
4886  ptr[(index >> 3)] &= bit_mask[index & 7];
4887  }
4888 
4889  inline std::size_t hamming_distance(const unsigned char* begin1, const unsigned char* end1,
4890  const unsigned char* begin2, const unsigned char* end2)
4891  {
4892  if (std::distance(begin1,end1) != std::distance(begin2,end2))
4893  {
4894  return std::numeric_limits<std::size_t>::max();
4895  }
4896 
4897  std::size_t distance = 0;
4898  const unsigned char* itr1 = begin1;
4899  const unsigned char* itr2 = begin2;
4900 
4901  while (end1 != itr1)
4902  {
4903  distance += high_bit_count(static_cast<unsigned char>(((*itr1++) ^ (*itr2++)) & 0xFF));
4904  }
4905 
4906  return distance;
4907  }
4908 
4909  inline std::size_t hamming_distance(const char* begin1, const char* end1,
4910  const char* begin2, const char* end2)
4911  {
4912  return hamming_distance(reinterpret_cast<const unsigned char*>(begin1),
4913  reinterpret_cast<const unsigned char*>(end1),
4914  reinterpret_cast<const unsigned char*>(begin2),
4915  reinterpret_cast<const unsigned char*>(end2));
4916  }
4917 
4918  inline std::size_t hamming_distance(const std::string& str1, const std::string& str2)
4919  {
4920  return hamming_distance(str1.data(), str1.data() + str1.size(),
4921  str2.data(), str2.data() + str2.size());
4922  }
4923 
4924  template <typename Iterator>
4925  inline std::size_t hamming_distance_elementwise(const Iterator begin1, const Iterator end1,
4926  const Iterator begin2, const Iterator end2)
4927  {
4928  if (std::distance(begin1,end1) != std::distance(begin2,end2))
4929  {
4930  return std::numeric_limits<std::size_t>::max();
4931  }
4932 
4933  std::size_t distance = 0;
4934  Iterator itr1 = begin1;
4935  Iterator itr2 = begin2;
4936 
4937  while (end1 != itr1)
4938  {
4939  if ((*itr1) != (*itr2))
4940  ++distance;
4941  }
4942 
4943  return distance;
4944  }
4945 
4946  inline std::size_t hamming_distance_elementwise(const std::string& str1, const std::string& str2)
4947  {
4948  return hamming_distance_elementwise(str1.data(), str1.data() + str1.size(),
4949  str2.data(), str2.data() + str2.size());
4950  }
4951 
4953  {
4954  public:
4955 
4956  typedef const unsigned char* iterator_t;
4957  typedef unsigned int index_t;
4958  typedef std::pair<iterator_t,iterator_t> range_t;
4959  typedef std::deque<range_t> token_list_t;
4960  typedef std::pair<index_t,index_t> row_index_range_t;
4961  typedef std::deque<row_index_range_t> row_index_t;
4962  typedef std::pair<index_t,index_t> row_range_t;
4963  typedef std::pair<index_t,index_t> col_range_t;
4964 
4965  private:
4966 
4967  struct store
4968  {
4969  store()
4970  : max_column(0)
4971  {}
4972 
4973  token_list_t token_list;
4974  row_index_t row_index;
4975  std::size_t max_column;
4976 
4977  inline void clear()
4978  {
4979  token_list.clear();
4980  row_index.clear();
4981  }
4982 
4983  inline range_t operator()(const std::size_t& col, const std::size_t& row) const
4984  {
4985  if (row < row_index.size())
4986  {
4987  const row_index_range_t& r = row_index[row];
4988  if (col < (r.second - r.first + 1))
4989  return *(token_list.begin() + (r.first + col));
4990  else
4991  return null_range();
4992  }
4993  else
4994  return null_range();
4995  }
4996 
4997  inline bool remove_row(const std::size_t& row)
4998  {
4999  if (row >= row_index.size()) return false;
5000  row_index_range_t& r = row_index[row];
5001  std::size_t number_of_tokens = r.second - r.first + 1;
5002  token_list_t::iterator remove_begin = token_list.begin() + r.first;
5003  token_list_t::iterator remove_end = token_list.begin() + r.first + number_of_tokens;
5004  token_list.erase(remove_begin,remove_end);
5005  row_index.erase(row_index.begin() + row);
5006  for (std::size_t i = row; i < row_index.size(); ++i)
5007  {
5008  row_index_range_t& r = row_index[i];
5009  r.first -= static_cast<unsigned int>(number_of_tokens);
5010  r.second -= static_cast<unsigned int>(number_of_tokens);
5011  }
5012  return true;
5013  }
5014 
5015  inline std::size_t token_count(const row_index_range_t& r) const
5016  {
5017  return (r.second - r.first + 1);
5018  }
5019 
5020  inline std::size_t token_count(const std::size_t& index) const
5021  {
5022  return token_count(row_index[index]);
5023  }
5024 
5025  inline bool remove_row_range(const std::size_t& r0, const std::size_t& r1)
5026  {
5027  if (r0 > r1)
5028  return false;
5029  else if (r0 >= row_index.size())
5030  return false;
5031  else if (r1 >= row_index.size())
5032  return false;
5033  std::size_t number_of_tokens = 0;
5034  for (std::size_t i = r0; i <= r1; ++i)
5035  {
5036  row_index_range_t& r = row_index[i];
5037  number_of_tokens += token_count(r);
5038  }
5039  row_index_range_t rr0 = row_index[r0];
5040  token_list_t::iterator remove_begin = token_list.begin() + rr0.first;
5041  token_list_t::iterator remove_end = token_list.begin() + rr0.first + number_of_tokens;
5042  token_list.erase(remove_begin,remove_end);
5043  row_index.erase(row_index.begin() + r0,row_index.begin() + r0 + (r1 - r0 + 1));
5044  for (std::size_t i = r0; i < row_index.size(); ++i)
5045  {
5046  row_index_range_t& r = row_index[i];
5047  r.first -= static_cast<unsigned int>(number_of_tokens);
5048  r.second -= static_cast<unsigned int>(number_of_tokens);
5049  }
5050  return true;
5051  }
5052 
5054  {
5055  std::size_t column;
5056  std::size_t counter;
5057  std::size_t remainder;
5058  std::size_t current_row;
5059 
5060  inline void update(store& idx)
5061  {
5062  current_row++;
5063  while (current_row < idx.row_index.size())
5064  {
5065  std::size_t number_of_tokens = idx.token_count(current_row);
5066  if (number_of_tokens > column)
5067  break;
5068  counter += number_of_tokens;
5069  ++current_row;
5070  }
5071  if (current_row < idx.row_index.size())
5072  {
5073  counter += column + remainder;
5074  row_index_range_t& r = idx.row_index[current_row];
5075  remainder = (r.second - r.first) - column;
5076  }
5077  else
5078  counter = std::numeric_limits<std::size_t>::max();
5079  }
5080 
5081  inline void process(store& idx)
5082  {
5083  token_list_t::iterator itr1 = idx.token_list.begin();
5084  token_list_t::iterator itr2 = idx.token_list.begin();
5085  token_list_t::iterator end = idx.token_list.end();
5086  counter = 0;
5087  remainder = 0;
5088  current_row = static_cast<std::size_t>(-1);
5089  update(idx);
5090  while (end != itr1)
5091  {
5092  while ((end != itr1) && (0 != counter))
5093  {
5094  if (itr1 != itr2)
5095  {
5096  (*itr2) = (*itr1);
5097  }
5098  ++itr1;
5099  ++itr2;
5100  --counter;
5101  }
5102  if (0 == counter)
5103  {
5104  update(idx);
5105  ++itr1;
5106  }
5107  }
5108  std::size_t remove_count = 0;
5109  idx.max_column = std::numeric_limits<std::size_t>::min();
5110  for (std::size_t i = 0; i < idx.row_index.size(); ++i)
5111  {
5112  row_index_range_t& r = idx.row_index[i];
5113  std::size_t token_count = (r.second - r.first + 1);
5114  r.first -= static_cast<unsigned int>(remove_count);
5115  if (token_count > column)
5116  {
5117  ++remove_count;
5118  }
5119  r.second -= static_cast<unsigned int>(remove_count);
5120  token_count = (r.second - r.first + 1);
5121  if (token_count > idx.max_column)
5122  idx.max_column = token_count;
5123  }
5124  idx.token_list.resize(idx.token_list.size() - remove_count);
5125  }
5126  };
5127 
5128  inline bool remove_column(const std::size_t& column)
5129  {
5130  if (column >= max_column) return false;
5131  remove_column_impl rc;
5132  rc.column = column;
5133  rc.process(*this);
5134  return true;
5135  }
5136 
5137  inline static range_t null_range()
5138  {
5139  static const range_t null_range_ = range_t(reinterpret_cast<const unsigned char*>(0),
5140  reinterpret_cast<const unsigned char*>(0));
5141  return null_range_;
5142  }
5143 
5144  };
5145 
5146  template <typename DelimiterPredicate = multiple_char_delimiter_predicate>
5147  struct row_processor
5148  {
5149  row_processor(store& idx,
5150  DelimiterPredicate& tp,
5152  : idx_(idx),
5153  row_start_index_(0),
5154  row_end_index_(0),
5155  token_predicate_(tp),
5156  split_mode_(split_mode)
5157  {
5158  idx_.max_column = std::numeric_limits<std::size_t>::min();
5159  }
5160 
5161  inline void operator()(const range_t& range)
5162  {
5163  if (0 == std::distance(range.first,range.second))
5164  return;
5165  row_start_index_ = idx_.token_list.size();
5166  std::size_t token_count = split(token_predicate_,
5167  range.first,range.second,
5168  std::back_inserter(idx_.token_list),
5169  split_mode_);
5170  row_end_index_ = row_start_index_ + token_count - 1;
5171  idx_.row_index.push_back(std::make_pair(row_start_index_,row_end_index_));
5172  if (token_count > idx_.max_column)
5173  idx_.max_column = token_count;
5174  }
5175 
5176  row_processor<DelimiterPredicate> operator=(const row_processor<DelimiterPredicate>&);
5177 
5178  store& idx_;
5179  std::size_t row_start_index_;
5180  std::size_t row_end_index_;
5181  DelimiterPredicate& token_predicate_;
5182  split_options::type split_mode_;
5183  };
5184 
5185  public:
5186 
5187  inline row_range_t range(std::size_t lower_bound,
5188  std::size_t upper_bound = std::numeric_limits<std::size_t>::max()) const
5189  {
5190  if (upper_bound == std::numeric_limits<std::size_t>::max())
5191  {
5192  upper_bound = dsv_index_.token_list.size();
5193  }
5194  else if (upper_bound > dsv_index_.token_list.size())
5195  {
5196  return row_range_t(std::numeric_limits<std::size_t>::max(),std::numeric_limits<std::size_t>::max());
5197  }
5198  else if (lower_bound > upper_bound)
5199  {
5200  return row_range_t(std::numeric_limits<std::size_t>::max(),std::numeric_limits<std::size_t>::max());
5201  }
5202  return row_range_t(lower_bound,upper_bound);
5203  }
5204 
5205  struct options
5206  {
5208  : row_split_option(split_options::compress_delimiters),
5209  column_split_option(split_options::compress_delimiters),
5210  row_delimiters("\n\r"),
5211  column_delimiters(",|;\t "),
5212  support_dquotes(false)
5213  {}
5214 
5216  split_options::type sco,
5217  const std::string& rd,
5218  const std::string& cd,
5219  const bool support_dq = false)
5220  : row_split_option(sro),
5221  column_split_option(sco),
5222  row_delimiters(rd),
5223  column_delimiters(cd),
5224  support_dquotes(support_dq)
5225  {}
5226 
5228  {
5229  column_split_option = option;
5230  return *this;
5231  }
5232 
5234  {
5235  row_split_option = option;
5236  return *this;
5237  }
5238 
5239  inline options& set_column_delimiters(const std::string& delimiters)
5240  {
5241  column_delimiters = delimiters;
5242  return *this;
5243  }
5244 
5245  inline options& set_row_delimiters(const std::string& delimiters)
5246  {
5247  row_delimiters = delimiters;
5248  return *this;
5249  }
5250 
5256  };
5257 
5258  class row_type
5259  {
5260  private:
5261 
5262  typedef std::pair<bool,row_type*> row_pair_type;
5263 
5264  public:
5265 
5267  : index_(std::numeric_limits<std::size_t>::max()),
5268  size_(0)
5269  {}
5270 
5271  row_type(const std::size_t& index,
5272  const store& dsv_index)
5273  : index_(index),
5274  size_ (dsv_index.token_count(index)),
5275  begin_(dsv_index.token_list.begin() + dsv_index.row_index[index].first)
5276  {}
5277 
5278  template <typename T>
5279  inline T operator[](const std::size_t& index) const
5280  {
5281  const range_t& range = *(begin_ + index);
5282  return string_to_type_converter<T>(range.first,range.second);
5283  }
5284 
5285  template <typename T>
5286  inline T get(const std::size_t& index) const
5287  {
5288  return operator[]<T>(index);
5289  }
5290 
5291  inline col_range_t all_columns() const
5292  {
5293  return col_range_t(0,static_cast<index_t>(size()));
5294  }
5295 
5296  inline range_t range() const
5297  {
5298  return range_t((*begin_).first,(*(begin_ + (size_ - 1))).second);
5299  }
5300 
5301  inline range_t token(const std::size_t& index) const
5302  {
5303  return *(begin_ + index);
5304  }
5305 
5306  inline std::size_t index() const
5307  {
5308  return index_;
5309  }
5310 
5311  inline std::size_t size() const
5312  {
5313  return size_;
5314  }
5315 
5316  inline std::size_t raw_length() const
5317  {
5318  std::size_t result = 0;
5319  token_list_t::const_iterator itr = begin_;
5320  for (std::size_t i = 0; i < size_; ++i, ++itr)
5321  {
5322  const range_t& range = (*itr);
5323  result += std::distance(range.first,range.second);
5324  }
5325  return result;
5326  }
5327 
5328  inline std::size_t raw_length(const std::size_t& column_index) const
5329  {
5330  const range_t& range = *(begin_ + column_index);
5331  return std::distance(range.first,range.second);
5332  }
5333 
5334  inline std::string as_string() const
5335  {
5336  std::string result;
5337  result.reserve(std::distance(begin_->first,(begin_ + (size_ - 1))->second));
5338  token_list_t::const_iterator itr = begin_;
5339  for (std::size_t i = 0; i < size_; ++i, ++itr)
5340  {
5341  const range_t& range = (*itr);
5342  result.append(range.first,range.second);
5343  }
5344  return result;
5345  }
5346 
5347  inline void as_string(std::string& out) const
5348  {
5349  out = as_string();
5350  }
5351 
5352  template <typename T0, typename T1, typename T2, typename T3,
5353  typename T4, typename T5, typename T6, typename T7,
5354  typename T8, typename T9>
5355  inline bool parse_with_index(const std::size_t& col0, const std::size_t& col1,
5356  const std::size_t& col2, const std::size_t& col3,
5357  const std::size_t& col4, const std::size_t& col5,
5358  const std::size_t& col6, const std::size_t& col7,
5359  const std::size_t& col8, const std::size_t& col9,
5360  T0& t0, T1& t1, T2& t2, T3& t3, T4& t4, T5& t5,
5361  T6& t6, T7& t7, T8& t8, T9& t9) const
5362  {
5363  if (!process(*(begin_ + col0),t0)) return false;
5364  if (!process(*(begin_ + col1),t1)) return false;
5365  if (!process(*(begin_ + col2),t2)) return false;
5366  if (!process(*(begin_ + col3),t3)) return false;
5367  if (!process(*(begin_ + col4),t4)) return false;
5368  if (!process(*(begin_ + col5),t5)) return false;
5369  if (!process(*(begin_ + col6),t6)) return false;
5370  if (!process(*(begin_ + col7),t7)) return false;
5371  if (!process(*(begin_ + col8),t8)) return false;
5372  if (!process(*(begin_ + col9),t9)) return false;
5373  return true;
5374  }
5375 
5376  template <typename T0, typename T1, typename T2, typename T3,
5377  typename T4, typename T5, typename T6, typename T7,
5378  typename T8>
5379  inline bool parse_with_index(const std::size_t& col0, const std::size_t& col1,
5380  const std::size_t& col2, const std::size_t& col3,
5381  const std::size_t& col4, const std::size_t& col5,
5382  const std::size_t& col6, const std::size_t& col7,
5383  const std::size_t& col8,
5384  T0& t0, T1& t1, T2& t2, T3& t3, T4& t4, T5& t5,
5385  T6& t6, T7& t7, T8& t8) const
5386  {
5387  if (!process(*(begin_ + col0),t0)) return false;
5388  if (!process(*(begin_ + col1),t1)) return false;
5389  if (!process(*(begin_ + col2),t2)) return false;
5390  if (!process(*(begin_ + col3),t3)) return false;
5391  if (!process(*(begin_ + col4),t4)) return false;
5392  if (!process(*(begin_ + col5),t5)) return false;
5393  if (!process(*(begin_ + col6),t6)) return false;
5394  if (!process(*(begin_ + col7),t7)) return false;
5395  if (!process(*(begin_ + col8),t8)) return false;
5396  return true;
5397  }
5398 
5399  template <typename T0, typename T1, typename T2, typename T3,
5400  typename T4, typename T5, typename T6, typename T7>
5401  inline bool parse_with_index(const std::size_t& col0, const std::size_t& col1,
5402  const std::size_t& col2, const std::size_t& col3,
5403  const std::size_t& col4, const std::size_t& col5,
5404  const std::size_t& col6, const std::size_t& col7,
5405  T0& t0, T1& t1, T2& t2, T3& t3, T4& t4, T5& t5,
5406  T6& t6, T7& t7) const
5407  {
5408  if (!process(*(begin_ + col0),t0)) return false;
5409  if (!process(*(begin_ + col1),t1)) return false;
5410  if (!process(*(begin_ + col2),t2)) return false;
5411  if (!process(*(begin_ + col3),t3)) return false;
5412  if (!process(*(begin_ + col4),t4)) return false;
5413  if (!process(*(begin_ + col5),t5)) return false;
5414  if (!process(*(begin_ + col6),t6)) return false;
5415  if (!process(*(begin_ + col7),t7)) return false;
5416  return true;
5417  }
5418 
5419  template <typename T0, typename T1, typename T2, typename T3,
5420  typename T4, typename T5, typename T6>
5421  inline bool parse_with_index(const std::size_t& col0, const std::size_t& col1,
5422  const std::size_t& col2, const std::size_t& col3,
5423  const std::size_t& col4, const std::size_t& col5,
5424  const std::size_t& col6,
5425  T0& t0, T1& t1, T2& t2, T3& t3, T4& t4, T5& t5,
5426  T6& t6) const
5427  {
5428  if (!process(*(begin_ + col0),t0)) return false;
5429  if (!process(*(begin_ + col1),t1)) return false;
5430  if (!process(*(begin_ + col2),t2)) return false;
5431  if (!process(*(begin_ + col3),t3)) return false;
5432  if (!process(*(begin_ + col4),t4)) return false;
5433  if (!process(*(begin_ + col5),t5)) return false;
5434  if (!process(*(begin_ + col6),t6)) return false;
5435  return true;
5436  }
5437 
5438  template <typename T0, typename T1, typename T2, typename T3,
5439  typename T4, typename T5>
5440  inline bool parse_with_index(const std::size_t& col0, const std::size_t& col1,
5441  const std::size_t& col2, const std::size_t& col3,
5442  const std::size_t& col4, const std::size_t& col5,
5443  T0& t0, T1& t1, T2& t2, T3& t3, T4& t4, T5& t5) const
5444  {
5445  if (!process(*(begin_ + col0),t0)) return false;
5446  if (!process(*(begin_ + col1),t1)) return false;
5447  if (!process(*(begin_ + col2),t2)) return false;
5448  if (!process(*(begin_ + col3),t3)) return false;
5449  if (!process(*(begin_ + col4),t4)) return false;
5450  if (!process(*(begin_ + col5),t5)) return false;
5451  return true;
5452  }
5453 
5454  template <typename T0, typename T1, typename T2, typename T3, typename T4>
5455  inline bool parse_with_index(const std::size_t& col0, const std::size_t& col1,
5456  const std::size_t& col2, const std::size_t& col3,
5457  const std::size_t& col4,
5458  T0& t0, T1& t1, T2& t2, T3& t3, T4& t4) const
5459  {
5460  if (!process(*(begin_ + col0),t0)) return false;
5461  if (!process(*(begin_ + col1),t1)) return false;
5462  if (!process(*(begin_ + col2),t2)) return false;
5463  if (!process(*(begin_ + col3),t3)) return false;
5464  if (!process(*(begin_ + col4),t4)) return false;
5465  return true;
5466  }
5467 
5468  template <typename T0, typename T1, typename T2, typename T3>
5469  inline bool parse_with_index(const std::size_t& col0, const std::size_t& col1,
5470  const std::size_t& col2, const std::size_t& col3,
5471  T0& t0, T1& t1, T2& t2, T3& t3) const
5472  {
5473  if (!process(*(begin_ + col0),t0)) return false;
5474  if (!process(*(begin_ + col1),t1)) return false;
5475  if (!process(*(begin_ + col2),t2)) return false;
5476  if (!process(*(begin_ + col3),t3)) return false;
5477  return true;
5478  }
5479 
5480  template <typename T0, typename T1, typename T2>
5481  inline bool parse_with_index(const std::size_t& col0, const std::size_t& col1,
5482  const std::size_t& col2,
5483  T0& t0, T1& t1, T2& t2) const
5484  {
5485  if (!process(*(begin_ + col0),t0)) return false;
5486  if (!process(*(begin_ + col1),t1)) return false;
5487  if (!process(*(begin_ + col2),t2)) return false;
5488  return true;
5489  }
5490 
5491  template <typename T0, typename T1>
5492  inline bool parse_with_index(const std::size_t& col0, const std::size_t& col1,
5493  T0& t0, T1& t1) const
5494  {
5495  if (!process(*(begin_ + col0),t0)) return false;
5496  if (!process(*(begin_ + col1),t1)) return false;
5497  return true;
5498  }
5499 
5500  template <typename T>
5501  inline bool parse_with_index(const std::size_t& col, T& t) const
5502  {
5503  return process(*(begin_ + col),t);
5504  }
5505 
5506  template <typename T0, typename T1, typename T2, typename T3,
5507  typename T4, typename T5, typename T6, typename T7,
5508  typename T8, typename T9 >
5509  inline bool parse(T0& t0, T1& t1, T2& t2, T3& t3,
5510  T4& t4, T5& t5, T6& t6, T7& t7,
5511  T8& t8, T9& t9) const
5512  {
5513  if (!process(*(begin_ + 0),t0)) return false;
5514  if (!process(*(begin_ + 1),t1)) return false;
5515  if (!process(*(begin_ + 2),t2)) return false;
5516  if (!process(*(begin_ + 3),t3)) return false;
5517  if (!process(*(begin_ + 4),t4)) return false;
5518  if (!process(*(begin_ + 5),t5)) return false;
5519  if (!process(*(begin_ + 6),t6)) return false;
5520  if (!process(*(begin_ + 7),t7)) return false;
5521  if (!process(*(begin_ + 8),t8)) return false;
5522  if (!process(*(begin_ + 9),t9)) return false;
5523  return true;
5524  }
5525 
5526  template <typename T0, typename T1, typename T2, typename T3,
5527  typename T4, typename T5, typename T6, typename T7,
5528  typename T8>
5529  inline bool parse(T0& t0, T1& t1, T2& t2, T3& t3,
5530  T4& t4, T5& t5, T6& t6, T7& t7,
5531  T8& t8) const
5532  {
5533  if (!process(*(begin_ + 0),t0)) return false;
5534  if (!process(*(begin_ + 1),t1)) return false;
5535  if (!process(*(begin_ + 2),t2)) return false;
5536  if (!process(*(begin_ + 3),t3)) return false;
5537  if (!process(*(begin_ + 4),t4)) return false;
5538  if (!process(*(begin_ + 5),t5)) return false;
5539  if (!process(*(begin_ + 6),t6)) return false;
5540  if (!process(*(begin_ + 7),t7)) return false;
5541  if (!process(*(begin_ + 8),t8)) return false;
5542  return true;
5543  }
5544 
5545  template <typename T0, typename T1, typename T2, typename T3,
5546  typename T4, typename T5, typename T6, typename T7>
5547  inline bool parse(T0& t0, T1& t1, T2& t2, T3& t3,
5548  T4& t4, T5& t5, T6& t6, T7& t7) const
5549  {
5550  if (!process(*(begin_ + 0),t0)) return false;
5551  if (!process(*(begin_ + 1),t1)) return false;
5552  if (!process(*(begin_ + 2),t2)) return false;
5553  if (!process(*(begin_ + 3),t3)) return false;
5554  if (!process(*(begin_ + 4),t4)) return false;
5555  if (!process(*(begin_ + 5),t5)) return false;
5556  if (!process(*(begin_ + 6),t6)) return false;
5557  if (!process(*(begin_ + 7),t7)) return false;
5558  return true;
5559  }
5560 
5561  template <typename T0, typename T1, typename T2, typename T3,
5562  typename T4, typename T5, typename T6>
5563  inline bool parse(T0& t0, T1& t1, T2& t2, T3& t3,
5564  T4& t4, T5& t5, T6& t6) const
5565  {
5566  if (!process(*(begin_ + 0),t0)) return false;
5567  if (!process(*(begin_ + 1),t1)) return false;
5568  if (!process(*(begin_ + 2),t2)) return false;
5569  if (!process(*(begin_ + 3),t3)) return false;
5570  if (!process(*(begin_ + 4),t4)) return false;
5571  if (!process(*(begin_ + 5),t5)) return false;
5572  if (!process(*(begin_ + 6),t6)) return false;
5573  return true;
5574  }
5575 
5576  template <typename T0, typename T1, typename T2, typename T3,
5577  typename T4, typename T5>
5578  inline bool parse(T0& t0, T1& t1, T2& t2, T3& t3,
5579  T4& t4, T5& t5) const
5580  {
5581  if (!process(*(begin_ + 0),t0)) return false;
5582  if (!process(*(begin_ + 1),t1)) return false;
5583  if (!process(*(begin_ + 2),t2)) return false;
5584  if (!process(*(begin_ + 3),t3)) return false;
5585  if (!process(*(begin_ + 4),t4)) return false;
5586  if (!process(*(begin_ + 5),t5)) return false;
5587  return true;
5588  }
5589 
5590  template <typename T0, typename T1,
5591  typename T2, typename T3,typename T4>
5592  inline bool parse(T0& t0, T1& t1, T2& t2, T3& t3, T4& t4) const
5593  {
5594  if (!process(*(begin_ + 0),t0)) return false;
5595  if (!process(*(begin_ + 1),t1)) return false;
5596  if (!process(*(begin_ + 2),t2)) return false;
5597  if (!process(*(begin_ + 3),t3)) return false;
5598  if (!process(*(begin_ + 4),t4)) return false;
5599  return true;
5600  }
5601 
5602  template <typename T0, typename T1,
5603  typename T2, typename T3>
5604  inline bool parse(T0& t0, T1& t1, T2& t2, T3& t3) const
5605  {
5606  if (!process(*(begin_ + 0),t0)) return false;
5607  if (!process(*(begin_ + 1),t1)) return false;
5608  if (!process(*(begin_ + 2),t2)) return false;
5609  if (!process(*(begin_ + 3),t3)) return false;
5610  return true;
5611  }
5612 
5613  template <typename T0, typename T1, typename T2>
5614  inline bool parse(T0& t0, T1& t1, T2& t2) const
5615  {
5616  if (!process(*(begin_ + 0),t0)) return false;
5617  if (!process(*(begin_ + 1),t1)) return false;
5618  if (!process(*(begin_ + 2),t2)) return false;
5619  return true;
5620  }
5621 
5622  template <typename T0, typename T1>
5623  inline bool parse(T0& t0, T1& t1) const
5624  {
5625  if (!process(*(begin_ + 0),t0)) return false;
5626  if (!process(*(begin_ + 1),t1)) return false;
5627  return true;
5628  }
5629 
5630  template <typename T0>
5631  inline bool parse(T0& t) const
5632  {
5633  return process(*begin_,t);
5634  }
5635 
5636  template <typename T, typename OutputIterator>
5637  inline void parse(OutputIterator out) const
5638  {
5639  token_list_t::const_iterator itr = begin_;
5640  const token_list_t::const_iterator end = begin_ + size_;
5641  while (end != itr)
5642  {
5643  const range_t& range = (*itr);
5644  *(out++) = string_to_type_converter<T>(range.first,range.second);
5645  ++itr;
5646  }
5647  }
5648 
5649  bool validate_column_range(const col_range_t& range) const
5650  {
5651  if ((range.first > size()) || (range.second > size()))
5652  return false;
5653  else if (range.first > range.second)
5654  return false;
5655  else
5656  return true;
5657  }
5658 
5659  col_range_t range(const std::size_t& lower_bound,
5660  const std::size_t& upper_bound = std::numeric_limits<std::size_t>::max()) const
5661  {
5662  if (std::numeric_limits<std::size_t>::max() != upper_bound)
5663  return col_range_t(lower_bound,upper_bound);
5664  else
5665  return col_range_t(lower_bound,static_cast<index_t>(size()));
5666  }
5667 
5668  template <typename T,
5669  typename Allocator,
5670  template <typename,typename> class Sequence>
5671  inline bool parse(const col_range_t& range,
5672  Sequence<T,Allocator>& sequence) const
5673  {
5674  if (!validate_column_range(range))
5675  return false;
5676  token_list_t::const_iterator itr = (begin_ + range.first);
5677  token_list_t::const_iterator end = (begin_ + range.second);
5678  T t;
5679  while (end != itr)
5680  {
5681  const range_t& range = (*itr);
5682  if (string_to_type_converter(range.first,range.second,t))
5683  sequence.push_back(t);
5684  else
5685  return false;
5686  ++itr;
5687  }
5688  return true;
5689  }
5690 
5691  template <typename T,
5692  typename Comparator,
5693  typename Allocator>
5694  inline bool parse(const col_range_t& range,
5695  std::set<T,Comparator,Allocator>& set) const
5696  {
5697  if (!validate_column_range(range))
5698  return false;
5699  token_list_t::const_iterator itr = (begin_ + range.first);
5700  token_list_t::const_iterator end = (begin_ + range.second);
5701  T t;
5702  while (end != itr)
5703  {
5704  const range_t& range = (*itr);
5705  if (string_to_type_converter(range.first,range.second,t))
5706  set.insert(t);
5707  else
5708  return false;
5709  ++itr;
5710  }
5711  return true;
5712  }
5713 
5714  template <typename T,
5715  typename Comparator,
5716  typename Allocator>
5717  inline bool parse(const col_range_t& range,
5718  std::multiset<T,Comparator,Allocator>& multiset) const
5719  {
5720  if (!validate_column_range(range))
5721  return false;
5722  token_list_t::const_iterator itr = (begin_ + range.first);
5723  token_list_t::const_iterator end = (begin_ + range.second);
5724  T t;
5725  while (end != itr)
5726  {
5727  const range_t& range = (*itr);
5728  if (string_to_type_converter(range.first,range.second,t))
5729  multiset.insert(t);
5730  else
5731  return false;
5732  ++itr;
5733  }
5734  return true;
5735  }
5736 
5737  template <typename T, typename Container>
5738  inline bool parse(const col_range_t& range,
5739  std::queue<T,Container>& queue) const
5740  {
5741  if (!validate_column_range(range))
5742  return false;
5743  token_list_t::const_iterator itr = (begin_ + range.first);
5744  token_list_t::const_iterator end = (begin_ + range.second);
5745  T t;
5746  while (end != itr)
5747  {
5748  const range_t& range = (*itr);
5749  if (string_to_type_converter(range.first,range.second,t))
5750  queue.push(t);
5751  else
5752  return false;
5753  ++itr;
5754  }
5755  return true;
5756  }
5757 
5758  template <typename T, typename Container>
5759  inline bool parse(const col_range_t& range,
5760  std::stack<T,Container>& stack) const
5761  {
5762  if (!validate_column_range(range))
5763  return false;
5764  token_list_t::const_iterator itr = (begin_ + range.first);
5765  token_list_t::const_iterator end = (begin_ + range.second);
5766  T t;
5767  while (end != itr)
5768  {
5769  const range_t& range = (*itr);
5770  if (string_to_type_converter(range.first,range.second,t))
5771  stack.push(t);
5772  else
5773  return false;
5774  ++itr;
5775  }
5776  return true;
5777  }
5778 
5779  template <typename T,
5780  typename Container,
5781  typename Comparator>
5782  inline bool parse(const col_range_t& range,
5783  std::priority_queue<T,Container,Comparator>& priority_queue) const
5784  {
5785  if (!validate_column_range(range))
5786  return false;
5787  token_list_t::const_iterator itr = (begin_ + range.first);
5788  token_list_t::const_iterator end = (begin_ + range.second);
5789  T t;
5790  while (end != itr)
5791  {
5792  const range_t& range = (*itr);
5793  if (string_to_type_converter(range.first,range.second,t))
5794  priority_queue.push(t);
5795  else
5796  return false;
5797  ++itr;
5798  }
5799  return true;
5800  }
5801 
5802  template <typename T,
5803  typename Allocator,
5804  template <typename,typename> class Sequence>
5805  inline bool parse(Sequence<T,Allocator>& sequence) const
5806  {
5807  return parse(range(0),sequence);
5808  }
5809 
5810  template <typename T,
5811  typename Comparator,
5812  typename Allocator>
5813  inline bool parse(std::set<T,Comparator,Allocator>& set) const
5814  {
5815  return parse(range(0),set);
5816  }
5817 
5818  template <typename T,
5819  typename Comparator,
5820  typename Allocator>
5821  inline bool parse(std::multiset<T,Comparator,Allocator>& multiset) const
5822  {
5823  return parse(range(0),multiset);
5824  }
5825 
5826  template <typename T, typename Container>
5827  inline bool parse(std::queue<T,Container>& queue) const
5828  {
5829  return parse(range(0),queue);
5830  }
5831 
5832  template <typename T, typename Container>
5833  inline bool parse(std::stack<T,Container>& stack) const
5834  {
5835  return parse(range(0),stack);
5836  }
5837 
5838  template <typename T,
5839  typename Container,
5840  typename Comparator>
5841  inline bool parse(std::priority_queue<T,Container,Comparator>& priority_queue) const
5842  {
5843  return parse(range(0),priority_queue);
5844  }
5845 
5846  template <typename T,
5847  typename Allocator,
5848  template <typename,typename> class Sequence>
5849  inline std::size_t parse_n(const std::size_t& n, Sequence<T,Allocator>& sequence) const
5850  {
5851  if (0 == n) return 0;
5852  T t;
5853  std::size_t count = 0;
5854  token_list_t::const_iterator itr = begin_;
5855  const token_list_t::const_iterator end = begin_ + size_;
5856  while (end != itr)
5857  {
5858  const range_t& range = (*itr);
5859  if (!string_to_type_converter(range.first,range.second,t))
5860  return false;
5861  else
5862  sequence.push_back(t);
5863  if (n == (++count))
5864  break;
5865  ++itr;
5866  }
5867  return count;
5868  }
5869 
5870  template <typename T, typename OutputIterator>
5871  inline void parse_checked(OutputIterator out) const
5872  {
5873  T value;
5874  token_list_t::const_iterator itr = begin_;
5875  const token_list_t::const_iterator end = begin_ + size_;
5876  while (end != itr)
5877  {
5878  const range_t& range = (*itr);
5879  if (string_to_type_converter(range.first,range.second,value))
5880  {
5881  *(out++) = value;
5882  }
5883  ++itr;
5884  }
5885  }
5886 
5887  template <typename T,
5888  typename Allocator,
5889  template <typename,typename> class Sequence>
5890  inline void parse_checked(Sequence<T,Allocator>& sequence) const
5891  {
5892  parse_checked<T>(std::back_inserter(sequence));
5893  }
5894 
5895  template <typename T,
5896  typename Comparator,
5897  typename Allocator>
5898  inline void parse_checked(std::set<T,Comparator,Allocator>& set) const
5899  {
5900  parse_checked<T>(std::inserter(set,set.end()));
5901  }
5902 
5903  template <typename T,
5904  typename Comparator,
5905  typename Allocator>
5906  inline void parse_checked(std::multiset<T,Comparator,Allocator>& multiset) const
5907  {
5908  parse_checked<T>(std::inserter(multiset,multiset.end()));
5909  }
5910 
5911  template <typename T, typename Container>
5912  inline void parse_checked(std::queue<T,Container>& queue) const
5913  {
5914  parse_checked<T>(push_inserter(queue));
5915  }
5916 
5917  template <typename T, typename Container>
5918  inline void parse_checked(std::stack<T,Container>& stack) const
5919  {
5920  parse_checked<T>(push_inserter(stack));
5921  }
5922 
5923  template <typename T,
5924  typename Container,
5925  typename Comparator>
5926  inline void parse_checked(std::priority_queue<T,Container,Comparator>& priority_queue) const
5927  {
5928  parse_checked<T>(push_inserter(priority_queue));
5929  }
5930 
5931  template <typename Function>
5932  inline std::size_t for_each_column(const col_range_t& range, Function f) const
5933  {
5934  if (!validate_column_range(range))
5935  return false;
5936  token_list_t::const_iterator itr = begin_ + range.first;
5937  token_list_t::const_iterator end = begin_ + range.second;
5938  std::size_t col_count = 0;
5939  while (end != itr)
5940  {
5941  const range_t& range = (*itr);
5942  f(range);
5943  ++itr;
5944  ++col_count;
5945  }
5946  return col_count;
5947  }
5948 
5949  template <typename Function>
5950  inline std::size_t for_each_column(Function f) const
5951  {
5952  return for_each_column(all_columns(),f);
5953  }
5954 
5955  private:
5956 
5957  template <typename T>
5958  inline bool process(const range_t& range, T& t) const
5959  {
5960  return string_to_type_converter(range.first,range.second,t);
5961  }
5962 
5963  private:
5964 
5965  std::size_t index_;
5966  std::size_t size_;
5967  token_list_t::const_iterator begin_;
5968  };
5969 
5971  : file_name_(""),
5972  buffer_(0),
5973  buffer_size_(0),
5974  min_column_count_(0),
5975  max_column_count_(0),
5976  load_from_file_(false),
5977  state_(false)
5978  {}
5979 
5980  token_grid(const std::string& file_name,
5982  : file_name_(file_name),
5983  buffer_(0),
5984  buffer_size_(0),
5985  min_column_count_(0),
5986  max_column_count_(0),
5987  options_(options),
5988  load_from_file_(true),
5989  state_(load())
5990  {}
5991 
5992  token_grid(const unsigned char* input_buffer,
5993  const std::size_t& input_buffer_size,
5995  : file_name_(""),
5996  buffer_(const_cast<unsigned char*>(input_buffer)),
5997  buffer_size_(input_buffer_size),
5998  min_column_count_(0),
5999  max_column_count_(0),
6000  options_(options),
6001  load_from_file_(false),
6002  state_(load())
6003  {}
6004 
6005  token_grid(const char* input_buffer,
6006  const std::size_t& input_buffer_size,
6008  : file_name_(""),
6009  buffer_(reinterpret_cast<unsigned char*>(const_cast<char*>(input_buffer))),
6010  buffer_size_(input_buffer_size),
6011  min_column_count_(0),
6012  max_column_count_(0),
6013  options_(options),
6014  load_from_file_(false),
6015  state_(load())
6016  {}
6017 
6018  token_grid(const std::string& input_buffer,
6019  const std::size_t& input_buffer_size,
6021  : file_name_(""),
6022  buffer_(reinterpret_cast<unsigned char*>(const_cast<char*>(input_buffer.data()))),
6023  buffer_size_(input_buffer_size),
6024  min_column_count_(0),
6025  max_column_count_(0),
6026  options_(options),
6027  load_from_file_(false),
6028  state_(load())
6029  {}
6030 
6031  token_grid(const std::string& file_name,
6032  const std::string& column_delimiters = ",|;\t",
6033  const std::string& row_delimiters = "\n\r")
6034  : file_name_(file_name),
6035  buffer_(0),
6036  buffer_size_(0),
6037  min_column_count_(0),
6038  max_column_count_(0),
6039  options_(split_options::compress_delimiters,
6040  split_options::compress_delimiters,
6041  row_delimiters,
6042  column_delimiters),
6043  load_from_file_(true),
6044  state_(load())
6045  {}
6046 
6047  token_grid(const unsigned char* input_buffer,
6048  const std::size_t& input_buffer_size,
6049  const std::string& column_delimiters = ",|;\t",
6050  const std::string& row_delimiters = "\n\r")
6051  : file_name_(""),
6052  buffer_(const_cast<unsigned char*>(input_buffer)),
6053  buffer_size_(input_buffer_size),
6054  min_column_count_(0),
6055  max_column_count_(0),
6056  options_(split_options::compress_delimiters,
6057  split_options::compress_delimiters,
6058  row_delimiters,
6059  column_delimiters),
6060  load_from_file_(false),
6061  state_(load())
6062  {}
6063 
6064  token_grid(const char* input_buffer,
6065  const std::size_t& input_buffer_size,
6066  const std::string& column_delimiters = ",|;\t",
6067  const std::string& row_delimiters = "\n\r")
6068  : file_name_(""),
6069  buffer_(reinterpret_cast<unsigned char*>(const_cast<char*>(input_buffer))),
6070  buffer_size_(input_buffer_size),
6071  min_column_count_(0),
6072  max_column_count_(0),
6073  options_(split_options::compress_delimiters,
6074  split_options::compress_delimiters,
6075  row_delimiters,
6076  column_delimiters),
6077  load_from_file_(false),
6078  state_(load())
6079  {}
6080 
6081  token_grid(const std::string& input_buffer,
6082  const std::size_t& input_buffer_size,
6083  const std::string& column_delimiters = ",;|\t ",
6084  const std::string& row_delimiters = "\n\r")
6085  : file_name_(""),
6086  buffer_(reinterpret_cast<unsigned char*>(const_cast<char*>(input_buffer.data()))),
6087  buffer_size_(input_buffer_size),
6088  min_column_count_(0),
6089  max_column_count_(0),
6090  options_(split_options::compress_delimiters,
6091  split_options::compress_delimiters,
6092  row_delimiters,
6093  column_delimiters),
6094  load_from_file_(false),
6095  state_(load())
6096  {}
6097 
6099  {
6100  if ((load_from_file_) && (0 != buffer_))
6101  {
6102  delete [] buffer_;
6103  buffer_ = 0;
6104  }
6105  }
6106 
6107  inline bool operator!() const
6108  {
6109  return !state_;
6110  }
6111 
6112  inline std::string source_file() const
6113  {
6114  return file_name_;
6115  }
6116 
6117  inline std::size_t row_count() const
6118  {
6119  return dsv_index_.row_index.size();
6120  }
6121 
6122  inline std::size_t min_column_count() const
6123  {
6124  return min_column_count_;
6125  }
6126 
6127  inline std::size_t max_column_count() const
6128  {
6129  return max_column_count_;
6130  }
6131 
6132  inline range_t token(const unsigned int& row, const std::size_t& col) const
6133  {
6134  return dsv_index_(col,row);
6135  }
6136 
6137  template <typename T>
6138  inline T get(const unsigned int& row, const std::size_t& col)
6139  {
6140  range_t r = token(row,col);
6141  return string_to_type_converter<T>(r.first,r.second);
6142  }
6143 
6144  inline row_type row(const unsigned int& row_index) const
6145  {
6146  return row_type(row_index,dsv_index_);
6147  }
6148 
6149  inline row_range_t all_rows() const
6150  {
6151  return row_range_t(0,static_cast<index_t>(dsv_index_.row_index.size()));
6152  }
6153 
6154  template <typename OutputIterator>
6155  inline bool extract_column_checked(const row_range_t& row_range,
6156  const std::size_t& index,
6157  OutputIterator out) const
6158  {
6159  if (index > max_column_count_)
6160  return false;
6161  else if (row_range_invalid(row_range))
6162  return false;
6163  for (std::size_t i = row_range.first; i < row_range.second; ++i)
6164  {
6165  const row_index_range_t& row = dsv_index_.row_index[i];
6166  if (index < dsv_index_.token_count(row))
6167  {
6168  dsv_index_.token_list.begin() + (row.first + index);
6169  process_token_checked(*(dsv_index_.token_list.begin() + (row.first + index)),out);
6170  }
6171  }
6172  return true;
6173  }
6174 
6175  template <typename OutputIterator>
6176  inline bool extract_column_checked(const std::size_t& index,
6177  OutputIterator out) const
6178  {
6179  return extract_column_checked(all_rows(),index,out);
6180  }
6181 
6182  template <typename T,
6183  typename Allocator,
6184  template <typename,typename> class Sequence>
6185  inline void extract_column_checked(const std::size_t& index,
6186  Sequence<T,Allocator>& sequence) const
6187  {
6189  }
6190 
6191  template <typename T,
6192  typename Comparator,
6193  typename Allocator>
6194  inline void extract_column_checked(const std::size_t& index,
6195  std::set<T,Comparator,Allocator>& set) const
6196  {
6198  }
6199 
6200  template <typename T,
6201  typename Comparator,
6202  typename Allocator>
6203  inline void extract_column_checked(const std::size_t& index,
6204  std::multiset<T,Comparator,Allocator>& multiset) const
6205  {
6207  }
6208 
6209  template <typename OutputIterator>
6210  inline bool extract_column(const row_range_t& row_range,
6211  const std::size_t& index,
6212  OutputIterator out) const
6213  {
6214 
6215  if (index > max_column_count_)
6216  return false;
6217  else if (row_range_invalid(row_range))
6218  return false;
6219  for (std::size_t i = row_range.first; i < row_range.second; ++i)
6220  {
6221  const row_index_range_t& row = dsv_index_.row_index[i];
6222  if (index < dsv_index_.token_count(row))
6223  {
6224  process_token(*(dsv_index_.token_list.begin() + (row.first + index)),out);
6225  }
6226  }
6227  return true;
6228  }
6229 
6230  template <typename OutputIterator>
6231  inline bool extract_column(const std::size_t& index,
6232  OutputIterator out) const
6233  {
6234  return extract_column(all_rows(),index,out);
6235  }
6236 
6237  template <typename OutputIterator0, typename OutputIterator1>
6238  inline bool extract_column(const row_range_t& row_range,
6239  const std::size_t& index0,
6240  const std::size_t& index1,
6241  OutputIterator0 out0,
6242  OutputIterator1 out1) const
6243  {
6244  if ((index0 > max_column_count_) ||
6245  (index1 > max_column_count_))
6246  return false;
6247  else if (row_range_invalid(row_range))
6248  return false;
6249  std::size_t max_index = std::max(index0,index1);
6250  for (std::size_t i = row_range.first; i < row_range.second; ++i)
6251  {
6252  const row_index_range_t& row = dsv_index_.row_index[i];
6253  if (max_index < dsv_index_.token_count(row))
6254  {
6255  process_token(*(dsv_index_.token_list.begin() + (row.first + index0)),out0);
6256  process_token(*(dsv_index_.token_list.begin() + (row.first + index1)),out1);
6257  }
6258  }
6259  return true;
6260  }
6261 
6262  template <typename OutputIterator0, typename OutputIterator1, typename OutputIterator2>
6263  inline bool extract_column(const row_range_t& row_range,
6264  const std::size_t& index0,
6265  const std::size_t& index1,
6266  const std::size_t& index2,
6267  OutputIterator0 out0,
6268  OutputIterator1 out1,
6269  OutputIterator2 out2) const
6270  {
6271  if ((index0 > max_column_count_) ||
6272  (index1 > max_column_count_) ||
6273  (index2 > max_column_count_))
6274  return false;
6275  else if (row_range_invalid(row_range))
6276  return false;
6277  std::size_t max_index = std::max(index0,std::max(index1,index2));
6278  for (std::size_t i = row_range.first; i < row_range.second; ++i)
6279  {
6280  const row_index_range_t& row = dsv_index_.row_index[i];
6281  if (max_index < dsv_index_.token_count(row))
6282  {
6283  process_token(*(dsv_index_.token_list.begin() + (row.first + index0)),out0);
6284  process_token(*(dsv_index_.token_list.begin() + (row.first + index1)),out1);
6285  process_token(*(dsv_index_.token_list.begin() + (row.first + index2)),out2);
6286  }
6287  }
6288  return true;
6289  }
6290 
6291  template <typename OutputIterator0, typename OutputIterator1,
6292  typename OutputIterator2, typename OutputIterator3>
6293  inline bool extract_column(const row_range_t& row_range,
6294  const std::size_t& index0,
6295  const std::size_t& index1,
6296  const std::size_t& index2,
6297  const std::size_t& index3,
6298  OutputIterator0 out0,
6299  OutputIterator1 out1,
6300  OutputIterator2 out2,
6301  OutputIterator3 out3) const
6302  {
6303  if ((index0 > max_column_count_) ||
6304  (index1 > max_column_count_) ||
6305  (index2 > max_column_count_) ||
6306  (index3 > max_column_count_))
6307  return false;
6308  else if (row_range_invalid(row_range))
6309  return false;
6310  std::size_t max_index = std::max(std::max(index0,index1),std::max(index2,index3));
6311  for (std::size_t i = row_range.first; i < row_range.second; ++i)
6312  {
6313  const row_index_range_t& row = dsv_index_.row_index[i];
6314  if (max_index < dsv_index_.token_count(row))
6315  {
6316  process_token(*(dsv_index_.token_list.begin() + (row.first + index0)),out0);
6317  process_token(*(dsv_index_.token_list.begin() + (row.first + index1)),out1);
6318  process_token(*(dsv_index_.token_list.begin() + (row.first + index2)),out2);
6319  process_token(*(dsv_index_.token_list.begin() + (row.first + index3)),out3);
6320  }
6321  }
6322  return true;
6323  }
6324 
6325  template <typename OutputIterator0, typename OutputIterator1,
6326  typename OutputIterator2, typename OutputIterator3,
6327  typename OutputIterator4>
6328  inline bool extract_column(const row_range_t& row_range,
6329  const std::size_t& index0,
6330  const std::size_t& index1,
6331  const std::size_t& index2,
6332  const std::size_t& index3,
6333  const std::size_t& index4,
6334  OutputIterator0 out0,
6335  OutputIterator1 out1,
6336  OutputIterator2 out2,
6337  OutputIterator3 out3,
6338  OutputIterator4 out4) const
6339  {
6340  if ((index0 > max_column_count_) ||
6341  (index1 > max_column_count_) ||
6342  (index2 > max_column_count_) ||
6343  (index3 > max_column_count_) ||
6344  (index4 > max_column_count_))
6345  return false;
6346  else if (row_range_invalid(row_range))
6347  return false;
6348  std::size_t max_index = std::max(index4,std::max(std::max(index0,index1),std::max(index2,index3)));
6349  for (std::size_t i = row_range.first; i < row_range.second; ++i)
6350  {
6351  const row_index_range_t& row = dsv_index_.row_index[i];
6352  if (max_index < dsv_index_.token_count(row))
6353  {
6354  process_token(*(dsv_index_.token_list.begin() + (row.first + index0)),out0);
6355  process_token(*(dsv_index_.token_list.begin() + (row.first + index1)),out1);
6356  process_token(*(dsv_index_.token_list.begin() + (row.first + index2)),out2);
6357  process_token(*(dsv_index_.token_list.begin() + (row.first + index3)),out3);
6358  process_token(*(dsv_index_.token_list.begin() + (row.first + index4)),out4);
6359  }
6360  }
6361  return true;
6362  }
6363 
6364  inline void remove_row(const std::size_t& index)
6365  {
6366  if (index < dsv_index_.row_index.size())
6367  {
6368  dsv_index_.remove_row(index);
6369  }
6370  }
6371 
6372  template <typename Predicate>
6373  inline bool remove_row_if(const row_range_t& row_range, Predicate predicate)
6374  {
6375  if (row_range_invalid(row_range))
6376  return false;
6377  std::size_t removed_token_count = 0;
6378  std::deque<std::size_t> remove_token_list;
6379  std::deque<std::size_t> remove_row_list;
6380  for (std::size_t i = row_range.first; i < row_range.second; ++i)
6381  {
6382  row_index_range_t& r = dsv_index_.row_index[i];
6383  std::size_t temp_r_first = r.first - removed_token_count;
6384  row_type row(i,dsv_index_);
6385  if (predicate(row))
6386  {
6387  remove_row_list.push_back(i);
6388  for (std::size_t j = r.first; j <= r.second; ++j)
6389  {
6390  remove_token_list.push_back(j);
6391  }
6392  removed_token_count += row.size();
6393  }
6394  r.first = static_cast<unsigned int>(temp_r_first);
6395  r.second -= static_cast<unsigned int>(removed_token_count);
6396  }
6397  for (std::size_t i = row_range.second; i < dsv_index_.row_index.size(); ++i)
6398  {
6399  row_index_range_t& r = dsv_index_.row_index[i];
6400  r.first -= static_cast<unsigned int>(removed_token_count);
6401  r.second -= static_cast<unsigned int>(removed_token_count);
6402  }
6403  if (!remove_row_list.empty())
6404  {
6405  remove_inplace(index_remover(remove_row_list),dsv_index_.row_index);
6406  }
6407  if (!remove_token_list.empty())
6408  {
6409  remove_inplace(index_remover(remove_token_list),dsv_index_.token_list);
6410  }
6411  return true;
6412  }
6413 
6414  template <typename Predicate>
6415  inline bool remove_row_if(Predicate predicate)
6416  {
6417  return remove_row_if(all_rows(),predicate);
6418  }
6419 
6420  template <typename Predicate>
6421  inline std::size_t remove_token_if(const row_range_t& row_range, Predicate predicate)
6422  {
6423  if (row_range_invalid(row_range))
6424  return 0;
6425  std::size_t removed_token_count = 0;
6426  std::deque<std::size_t> remove_token_list;
6427  std::deque<std::size_t> remove_row_list;
6428  for (std::size_t i = row_range.first; i < row_range.second; ++i)
6429  {
6430  row_index_range_t& r = dsv_index_.row_index[i];
6431  std::size_t temp_r_first = r.first - removed_token_count;
6432  row_type row(i,dsv_index_);
6433  for (std::size_t j = 0; j < row.size(); ++j)
6434  {
6435  if (predicate(row.token(j)))
6436  {
6437  remove_token_list.push_back(r.first + j);
6438  ++removed_token_count;
6439  }
6440  }
6441  r.first = static_cast<unsigned int>(temp_r_first);
6442  r.second -= static_cast<unsigned int>(removed_token_count);
6443  if (0 == dsv_index_.token_count(r))
6444  {
6445  remove_row_list.push_back(i);
6446  }
6447  }
6448  for (std::size_t i = row_range.second; i < dsv_index_.row_index.size(); ++i)
6449  {
6450  row_index_range_t& r = dsv_index_.row_index[i];
6451  r.first -= static_cast<unsigned int>(removed_token_count);
6452  r.second -= static_cast<unsigned int>(removed_token_count);
6453  }
6454  if (!remove_row_list.empty())
6455  {
6456  remove_inplace(index_remover(remove_row_list),dsv_index_.row_index);
6457  }
6458  if (!remove_token_list.empty())
6459  {
6460  remove_inplace(index_remover(remove_token_list),dsv_index_.token_list);
6461  }
6462  if (!remove_token_list.empty())
6463  {
6464  update_minmax_columns();
6465  }
6466  return remove_token_list.size();
6467  }
6468 
6469  inline std::size_t remove_empty_tokens(const row_range_t& range)
6470  {
6471  return remove_token_if(range,is_empty_token());
6472  }
6473 
6474  inline std::size_t remove_empty_tokens()
6475  {
6476  return remove_empty_tokens(all_rows());
6477  }
6478 
6479  inline void enforce_column_count(const row_range_t& row_range,
6480  const std::size_t& column_count)
6481  {
6482  if (row_range_invalid(row_range))
6483  return;
6484  remove_row_if(insufficient_number_of_columns(column_count));
6485  min_column_count_ = column_count;
6486  max_column_count_ = column_count;
6487  }
6488 
6489  inline void enforce_column_count(const std::size_t& column_count)
6490  {
6491  enforce_column_count(all_rows(),column_count);
6492  }
6493 
6494  inline void enforce_min_max_column_count(const row_range_t& row_range,
6495  const std::size_t& min_column_count,
6496  const std::size_t& max_column_count)
6497  {
6498  if (row_range_invalid(row_range))
6499  return;
6500  remove_row_if(insufficient_number_of_minmax_columns(min_column_count,max_column_count));
6501  min_column_count_ = min_column_count;
6502  max_column_count_ = max_column_count;
6503  }
6504 
6505  inline void enforce_min_max_column_count(const std::size_t& min_column_count,
6506  const std::size_t& max_column_count)
6507  {
6508  enforce_min_max_column_count(all_rows(),min_column_count,max_column_count);
6509  }
6510 
6511  inline void clear(const bool force_delete_buffer = false)
6512  {
6513  if (load_from_file_ || force_delete_buffer)
6514  delete[] buffer_;
6515  buffer_ = 0;
6516  buffer_size_ = 0;
6517  dsv_index_.clear();
6518  min_column_count_ = 0;
6519  max_column_count_ = 0;
6520  state_ = false;
6521  file_name_ = "";
6522  }
6523 
6524  template <typename T>
6525  inline std::size_t accumulate_row(const std::size_t& row, T& result) const
6526  {
6527  if (row >= dsv_index_.row_index.size())
6528  return 0;
6529  const row_index_range_t& r = dsv_index_.row_index[row];
6530  token_list_t::const_iterator itr = dsv_index_.token_list.begin() + r.first;
6531  token_list_t::const_iterator end = dsv_index_.token_list.begin() + r.second + 1;
6532  std::size_t process_count = 0;
6533  T current_value = T();
6534  while (end != itr)
6535  {
6536  if (string_to_type_converter((*itr).first,(*itr).second,current_value))
6537  {
6538  result += current_value;
6539  ++process_count;
6540  }
6541  else
6542  return 0;
6543  ++itr;
6544  }
6545  return process_count;
6546  }
6547 
6548  template <typename T>
6549  inline std::size_t accumulate_column(const std::size_t& col,
6550  const row_range_t& row_range,
6551  T& result) const
6552  {
6553  if (col > max_column_count_)
6554  return 0;
6555  else if (row_range_invalid(row_range))
6556  return 0;
6557  std::size_t process_count = 0;
6558  T current_value = T();
6559  for (std::size_t i = row_range.first; i < row_range.second; ++i)
6560  {
6561  const row_index_range_t& r = dsv_index_.row_index[i];
6562  if (col < dsv_index_.token_count(r))
6563  {
6564  const range_t& range = *(dsv_index_.token_list.begin() + r.first + col);
6565  if (string_to_type_converter(range.first,range.second,current_value))
6566  result += current_value;
6567  else
6568  return 0;
6569  }
6570  ++process_count;
6571  }
6572  return process_count;
6573  }
6574 
6575  template <typename T>
6576  inline std::size_t accumulate_column(const std::size_t& col, T& result) const
6577  {
6578  return accumulate_column(col,all_rows(),result);
6579  }
6580 
6581  template <typename T, typename Predicate>
6582  inline std::size_t accumulate_column(const std::size_t& col,
6583  const row_range_t& row_range,
6584  Predicate p,
6585  T& result) const
6586  {
6587  if (col > max_column_count_)
6588  return 0;
6589  else if (row_range_invalid(row_range))
6590  return 0;
6591  std::size_t process_count = 0;
6592  T current_value = T();
6593  for (std::size_t i = row_range.first; i < row_range.second; ++i)
6594  {
6595  const row_index_range_t& r = dsv_index_.row_index[i];
6596  if (col < dsv_index_.token_count(r))
6597  {
6598  row_type row = row_type(i,dsv_index_);
6599  if (p(row))
6600  {
6601  const range_t& range = row.token(col);
6602  if (string_to_type_converter(range.first,range.second,current_value))
6603  {
6604  result += current_value;
6605  ++process_count;
6606  }
6607  else
6608  return 0;
6609  }
6610  }
6611 
6612  }
6613  return process_count;
6614  }
6615 
6616  template <typename T, typename Predicate>
6617  inline std::size_t accumulate_column(const std::size_t& col,
6618  Predicate p,
6619  T& result) const
6620  {
6621  return accumulate_column(col,all_rows(),p,result);
6622  }
6623 
6624  inline bool join_row(const std::size_t& row,
6625  const std::string& delimiter,
6626  std::string& result)
6627  {
6628  if (row >= dsv_index_.row_index.size())
6629  return false;
6630  const row_index_range_t& r = dsv_index_.row_index[row];
6631  token_list_t::const_iterator itr = dsv_index_.token_list.begin() + r.first;
6632  token_list_t::const_iterator end = dsv_index_.token_list.begin() + r.second + (row < (dsv_index_.row_index.size() - 1) ? 1 : 0);
6633  result.reserve(delimiter.size() * dsv_index_.token_count(r) + std::distance(itr->first,end->second));
6634  bool appended = false;
6635  while (end != itr)
6636  {
6637  if (!delimiter.empty() && appended)
6638  result.append(delimiter);
6639  appended = false;
6640  if ((*itr).first != (*itr).second)
6641  {
6642  result.append((*itr).first,(*itr).second);
6643  appended = true;
6644  }
6645  ++itr;
6646  }
6647  return true;
6648  }
6649 
6650  template <typename Predicate>
6651  inline bool join_row(const std::size_t& row,
6652  Predicate predicate,
6653  const std::string& delimiter,
6654  std::string& result)
6655  {
6656  if (row >= dsv_index_.row_index.size())
6657  return false;
6658  const row_index_range_t& r = dsv_index_.row_index[row];
6659  token_list_t::const_iterator itr = (dsv_index_.token_list.begin() + r.first);
6660  token_list_t::const_iterator end = dsv_index_.token_list.begin() + r.second + (row < (dsv_index_.row_index.size() - 1) ? 1 : 0);
6661  result.reserve(delimiter.size() * dsv_index_.token_count(r) + std::distance(itr->first,end->second));
6662  bool appended = false;
6663  while (end != itr)
6664  {
6665  if (!delimiter.empty() && appended)
6666  result.append(delimiter);
6667  appended = false;
6668  if ((*itr).first != (*itr).second)
6669  {
6670  if (predicate(*itr))
6671  {
6672  result.append((*itr).first,(*itr).second);
6673  appended = true;
6674  }
6675  }
6676  ++itr;
6677  }
6678  return true;
6679  }
6680 
6681  template <typename Predicate>
6682  inline bool join_row(const std::size_t& row,
6683  Predicate predicate,
6684  const char* delimiter,
6685  std::string& result)
6686  {
6687  return join_row(row,predicate,std::string(delimiter),result);
6688  }
6689 
6690  inline bool join_column(const std::size_t& col,
6691  const row_range_t& row_range,
6692  const std::string& delimiter,
6693  std::string& result) const
6694  {
6695  if (col > max_column_count_)
6696  return false;
6697  else if (row_range_invalid(row_range))
6698  return false;
6699  bool appended = false;
6700  for (std::size_t i = row_range.first; i < row_range.second; ++i)
6701  {
6702  const row_index_range_t& r = dsv_index_.row_index[i];
6703  if (col < dsv_index_.token_count(r))
6704  {
6705  row_type row = row_type(i,dsv_index_);
6706  const range_t& range = row.token(col);
6707  if (!delimiter.empty() && appended)
6708  result.append(delimiter);
6709  appended = false;
6710  if (range.first != range.second)
6711  {
6712  result.append(range.first,range.second);
6713  appended = true;
6714  }
6715  }
6716  }
6717  return true;
6718  }
6719 
6720  inline bool join_column(const std::size_t& col,
6721  const std::string& delimiter,
6722  std::string& result) const
6723  {
6724  return join_column(col,all_rows(),delimiter,result);
6725  }
6726 
6727  template <typename Predicate>
6728  inline bool join_column(const std::size_t& col,
6729  const row_range_t& row_range,
6730  Predicate predicate,
6731  const std::string& delimiter,
6732  std::string& result) const
6733  {
6734  if (col > max_column_count_)
6735  return false;
6736  else if (row_range_invalid(row_range))
6737  return false;
6738  bool appended = false;
6739  const std::size_t pre_end_index = row_range.second - 1;
6740  for (std::size_t i = row_range.first; i < row_range.second; ++i)
6741  {
6742  const row_index_range_t& r = dsv_index_.row_index[i];
6743  if (col < dsv_index_.token_count(r))
6744  {
6745  row_type row = row_type(i,dsv_index_);
6746  const range_t& range = row.token(col);
6747  if (!delimiter.empty() && appended && (pre_end_index != i))
6748  result.append(delimiter);
6749  appended = false;
6750  if (range.first != range.second)
6751  {
6752  if (predicate(row))
6753  {
6754  result.append(range.first,range.second);
6755  appended = true;
6756  }
6757  }
6758  }
6759  }
6760  return true;
6761  }
6762 
6763  template <typename Predicate>
6764  inline bool join_column(const std::size_t& col,
6765  Predicate p,
6766  const std::string& delimiter,
6767  std::string& result) const
6768  {
6769  return join_column(col,all_rows(),p,delimiter,result);
6770  }
6771 
6772  template <typename TransitionPredicate, typename Function>
6773  inline bool sequential_partition(const row_range_t& row_range,
6774  TransitionPredicate p,
6775  Function f)
6776  {
6777  if (row_range_invalid(row_range))
6778  return false;
6779  row_range_t r(row_range.first,row_range.first);
6780  for (std::size_t i = row_range.first; i < row_range.second; ++i)
6781  {
6782  if (p(row_type(i,dsv_index_)))
6783  {
6784  if (r.first != r.second)
6785  {
6786  r.second = i;
6787  if (!f(*this,r))
6788  return false;
6789  }
6790  r.first = r.second;
6791  }
6792  else
6793  r.second = i;
6794  }
6795  if (r.first != row_range.second)
6796  {
6797  r.second = row_range.second;
6798  if (!f(*this,r))
6799  return false;
6800  }
6801  return true;
6802  }
6803 
6804  template <typename TransitionPredicate, typename Function>
6805  inline bool sequential_partition(TransitionPredicate p, Function f)
6806  {
6807  return sequential_partition(all_rows(),p,f);
6808  }
6809 
6811  {
6812  return options();
6813  }
6814 
6815  template <typename Function>
6816  inline std::size_t for_each_row(const row_range_t& row_range, Function f) const
6817  {
6818  if (row_range_invalid(row_range))
6819  return 0;
6820  std::size_t row_count = 0;
6821  for (std::size_t i = row_range.first; i < row_range.second; ++i)
6822  {
6823  f(row_type(i,dsv_index_));
6824  ++row_count;
6825  }
6826  return row_count;
6827  }
6828 
6829  template <typename Function>
6830  inline std::size_t for_each_row(Function f) const
6831  {
6832  return for_each_row(all_rows(),f);
6833  }
6834 
6835  bool load(const std::string& file_name,
6837  {
6838  file_name_ = file_name;
6839  if ((load_from_file_) && (0 != buffer_))
6840  {
6841  delete [] buffer_;
6842  buffer_ = 0;
6843  }
6844  buffer_size_ = 0;
6845  min_column_count_ = 0;
6846  max_column_count_ = 0;
6847  options_ = options;
6848  load_from_file_ = true;
6849  state_ = load();
6850  if (state_)
6851  return true;
6852  else
6853  {
6854  file_name_ = "";
6855  if ((load_from_file_) && (0 != buffer_))
6856  {
6857  delete [] buffer_;
6858  buffer_ = 0;
6859  }
6860  return false;
6861  }
6862  }
6863 
6864  bool load(unsigned char* buffer,
6865  const std::size_t buffer_size,
6867  {
6868  file_name_ = "";
6869  if ((load_from_file_) && (0 != buffer_))
6870  {
6871  delete [] buffer_;
6872  buffer_ = 0;
6873  }
6874  min_column_count_ = 0;
6875  max_column_count_ = 0;
6876  options_ = options;
6877  load_from_file_ = false;
6878  buffer_ = buffer;
6879  buffer_size_ = buffer_size;
6880  state_ = load();
6881  if (state_)
6882  return true;
6883  else
6884  {
6885  file_name_ = "";
6886  if ((load_from_file_) && (0 != buffer_))
6887  {
6888  delete [] buffer_;
6889  buffer_ = 0;
6890  }
6891  return false;
6892  }
6893  }
6894 
6895  private:
6896 
6897  token_grid(const token_grid& tg);
6898  token_grid& operator=(const token_grid& tg);
6899 
6900  struct is_empty_token
6901  {
6902  inline bool operator()(const range_t& r) const
6903  {
6904  return r.first == r.second;
6905  }
6906  };
6907 
6908  struct insufficient_number_of_columns
6909  {
6910  insufficient_number_of_columns(const std::size_t& noc)
6911  : num_of_cols(noc)
6912  {}
6913 
6914  inline bool operator()(const row_type& row) const
6915  {
6916  return (num_of_cols != row.size());
6917  }
6918 
6919  std::size_t num_of_cols;
6920  };
6921 
6922  struct insufficient_number_of_minmax_columns
6923  {
6924  insufficient_number_of_minmax_columns(const std::size_t& min_col, const std::size_t& max_col)
6925  : min_column_count(min_col),
6926  max_column_count(max_col)
6927  {}
6928 
6929  inline bool operator()(const row_type& row) const
6930  {
6931  return (row.size() < min_column_count) || (max_column_count < row.size());
6932  }
6933 
6934  std::size_t min_column_count;
6935  std::size_t max_column_count;
6936  };
6937 
6938  class double_quotes_predicate
6939  {
6940  public:
6941 
6942  double_quotes_predicate(const std::string& delimiters)
6943  : in_bracket_range_(false),
6944  mdp_(delimiters)
6945  {}
6946 
6947  inline bool operator()(const unsigned char c) const
6948  {
6949  if ('"' == c)
6950  {
6951  in_bracket_range_ = !in_bracket_range_;
6952  return true;
6953  }
6954  else if (in_bracket_range_)
6955  return false;
6956  else
6957  return mdp_(c);
6958  }
6959 
6960  inline void reset()
6961  {
6962  in_bracket_range_ = false;
6963  }
6964 
6965  private:
6966 
6967  mutable bool in_bracket_range_;
6969  };
6970 
6971  inline bool load()
6972  {
6973  if (load_from_file_ && !load_buffer_from_file())
6974  return false;
6975 
6976  dsv_index_.token_list.clear();
6977  dsv_index_.row_index.clear();
6978 
6979  multiple_char_delimiter_predicate text_newline_predicate(options_.row_delimiters);
6980 
6981  if (!options_.support_dquotes)
6982  {
6983  multiple_char_delimiter_predicate token_predicate(options_.column_delimiters);
6984  strtk::split(text_newline_predicate,
6985  buffer_, buffer_ + buffer_size_,
6987  row_processor<multiple_char_delimiter_predicate>(dsv_index_,token_predicate,options_.column_split_option)),
6989  }
6990  else
6991  {
6992  double_quotes_predicate token_predicate_dblq(options_.column_delimiters);
6993  strtk::split(text_newline_predicate,
6994  buffer_, buffer_ + buffer_size_,
6996  row_processor<double_quotes_predicate>(dsv_index_,token_predicate_dblq,options_.column_split_option)),
6998  }
6999  update_minmax_columns();
7000  return true;
7001  }
7002 
7003  inline bool load_buffer_from_file()
7004  {
7005  std::ifstream stream(file_name_.c_str(),std::ios::binary);
7006  if (!stream)
7007  return false;
7008  stream.seekg (0,std::ios::end);
7009  buffer_size_ = static_cast<std::size_t>(stream.tellg());
7010  if (0 == buffer_size_)
7011  return false;
7012  stream.seekg (0,std::ios::beg);
7013  buffer_ = new unsigned char[buffer_size_];
7014  stream.read(reinterpret_cast<char*>(buffer_),static_cast<std::streamsize>(buffer_size_));
7015  stream.close();
7016  return true;
7017  }
7018 
7019  template <typename OutputIterator>
7020  inline void process_token(const range_t& range, OutputIterator out) const
7021  {
7022  typedef typename std::iterator_traits<OutputIterator>::value_type output_type;
7023  (*out) = string_to_type_converter<output_type>(range.first,range.second);
7024  ++out;
7025  }
7026 
7027  template <typename OutputIterator>
7028  inline void process_token_checked(const range_t& range, OutputIterator out) const
7029  {
7030  typedef typename std::iterator_traits<OutputIterator>::value_type output_type;
7031  output_type value;
7032  if (string_to_type_converter(range.first,range.second,value))
7033  {
7034  (*out) = value;
7035  ++out;
7036  }
7037  }
7038 
7039  inline bool row_range_invalid(const row_range_t& row_range) const
7040  {
7041  if (row_range.first > dsv_index_.row_index.size())
7042  return true;
7043  else if (row_range.second > dsv_index_.row_index.size())
7044  return true;
7045  else if (row_range.first > row_range.second)
7046  return true;
7047  else
7048  return false;
7049  }
7050 
7051  inline void update_minmax_columns()
7052  {
7053  min_column_count_ = std::numeric_limits<std::size_t>::max();
7054  max_column_count_ = std::numeric_limits<std::size_t>::min();
7055  for (std::size_t i = 0; i < dsv_index_.row_index.size(); ++i)
7056  {
7057  const row_index_range_t& r = dsv_index_.row_index[i];
7058  const std::size_t number_of_tokens = dsv_index_.token_count(r);
7059  if (number_of_tokens > max_column_count_)
7060  max_column_count_ = number_of_tokens;
7061  if (number_of_tokens < min_column_count_)
7062  min_column_count_ = number_of_tokens;
7063  }
7064  }
7065 
7066  private:
7067 
7068  store dsv_index_;
7069  std::string file_name_;
7070  unsigned char* buffer_;
7071  std::size_t buffer_size_;
7072  std::size_t min_column_count_;
7073  std::size_t max_column_count_;
7074  options options_;
7075  bool load_from_file_;
7076  bool state_;
7077  };
7078 
7079  template <typename T>
7080  inline bool convert_string_range(const std::pair<std::string::const_iterator,std::string::const_iterator>& range, T& t)
7081  {
7082  if (range.first == range.second) return false;
7083  t = string_to_type_converter<T>(std::string(range.first,range.second));
7084  return true;
7085  }
7086 
7088  {
7089  public:
7090 
7091  template <typename InputIterator>
7092  inline bool operator()(const InputIterator begin, const InputIterator end)
7093  {
7094  return (0 == std::distance(begin,end));
7095  }
7096  };
7097 
7099  {
7100  public:
7101 
7102  template <typename InputIterator>
7103  inline bool operator()(const InputIterator begin, const InputIterator end)
7104  {
7105  return (0 != std::distance(begin,end));
7106  }
7107  };
7108 
7109  template <typename OutputIterator>
7111  {
7112  public:
7113 
7115  : out_(out)
7116  {}
7117 
7118  template <typename Iterator>
7119  inline void operator() (const std::pair<Iterator,Iterator>& range)
7120  {
7121  if (range.first != range.second)
7122  {
7123  *out_++ = range;
7124  }
7125  }
7126 
7127  private:
7128 
7129  OutputIterator out_;
7130  };
7131 
7132  template <typename OutputPredicate>
7134  {
7135  public:
7136 
7138  OutputPredicate& predicate,
7139  bool allow_through_on_match = true)
7140  : allow_through_on_match_(allow_through_on_match),
7141  match_pattern_(match_pattern),
7142  predicate_(predicate)
7143  {}
7144 
7145  template <typename Iterator>
7146  inline void operator() (const std::pair<Iterator,Iterator>& range) const
7147  {
7148  if (match(match_pattern_.begin(),match_pattern_.end(),range.first,range.second,'*','?') ^ allow_through_on_match_)
7149  {
7150  predicate_(range);
7151  }
7152  }
7153 
7154  inline void operator() (const std::string& s) const
7155  {
7156  if (match(match_pattern_,s) ^ allow_through_on_match_)
7157  {
7158  predicate_(s);
7159  }
7160  }
7161 
7162  private:
7163 
7165  filter_on_wildcard_match& operator=(const filter_on_wildcard_match& fom);
7166 
7167  bool allow_through_on_match_;
7168  std::string match_pattern_;
7169  OutputPredicate& predicate_;
7170  };
7171 
7172  template <typename OutputPredicate>
7174  {
7175  public:
7176 
7177  filter_on_match(const std::string* begin, const std::string* end,
7178  OutputPredicate predicate,
7179  bool case_insensitive,
7180  bool allow_through_on_match = true)
7181  : case_insensitive_(case_insensitive),
7182  allow_through_on_match_(allow_through_on_match),
7183  begin_(begin),
7184  end_(end),
7185  predicate_(predicate)
7186  {}
7187 
7188  template <typename Iterator>
7189  inline void operator() (const std::pair<Iterator,Iterator>& range) const
7190  {
7191  for (const std::string* itr = begin_; end_ != itr; ++itr)
7192  {
7193  if ((case_insensitive_ &&
7194  (imatch((*itr).data(),(*itr).data() + (*itr).size(),range.first,range.second))) ||
7195  (!case_insensitive_ && std::equal((*itr).begin(),(*itr).end(),range.first)))
7196  {
7197  if (allow_through_on_match_)
7198  {
7199  predicate_(range);
7200  }
7201  return;
7202  }
7203  }
7204 
7205  if (!allow_through_on_match_)
7206  {
7207  predicate_(range);
7208  return;
7209  }
7210  }
7211 
7212  inline void operator() (const std::string& s) const
7213  {
7214  for (const std::string* itr = begin_; end_ != itr; ++itr)
7215  {
7216  if ((case_insensitive_ &&
7217  (imatch((*itr).begin(),(*itr).end(),s.begin(),s.end()))) ||
7218  (!case_insensitive_ && std::equal((*itr).begin(),(*itr).end(),s.begin())))
7219  {
7220  if (allow_through_on_match_)
7221  {
7222  predicate_(s);
7223  return;
7224  }
7225  }
7226  }
7227 
7228  if (!allow_through_on_match_)
7229  {
7230  predicate_(s);
7231  return;
7232  }
7233  }
7234 
7235  private:
7236 
7237  filter_on_match& operator=(const filter_on_match& fom);
7238 
7239  private:
7240 
7241  bool case_insensitive_;
7242  bool allow_through_on_match_;
7243  const std::string* begin_;
7244  const std::string* end_;
7245  OutputPredicate predicate_;
7246  };
7247 
7248  template <typename Iterator, typename MatchPredicate>
7249  inline void skip_while_matching(Iterator& itr,
7250  const Iterator& end,
7251  const MatchPredicate& predicate)
7252  {
7253  while (end != itr)
7254  {
7255  if (predicate(*itr))
7256  ++itr;
7257  else
7258  break;
7259  }
7260  }
7261 
7262  template <std::size_t length>
7264  {
7265  template <typename Iterator>
7266  inline bool operator()(const Iterator begin, const Iterator end) const
7267  {
7268  return length == std::distance(begin,end);
7269  }
7270 
7271  template <typename Iterator>
7272  inline bool operator()(const std::pair<Iterator,Iterator>& range) const
7273  {
7274  return length == std::distance(range.first,range.second);
7275  }
7276 
7277  template <typename T,
7278  typename Allocator,
7279  template <typename,typename> class Sequence>
7280  inline bool operator()(const Sequence<T,Allocator>& sequence) const
7281  {
7282  return length == sequence.size();
7283  }
7284 
7285  template <typename T,
7286  typename Comparator,
7287  typename Allocator>
7288  inline bool operator()(const std::set<T,Comparator,Allocator>& set) const
7289  {
7290  return length == set.size();
7291  }
7292 
7293  template <typename T,
7294  typename Comparator,
7295  typename Allocator>
7296  inline bool operator()(const std::multiset<T,Comparator,Allocator>& multiset) const
7297  {
7298  return length == multiset.size();
7299  }
7300 
7301  inline bool operator()(const std::string& str) const
7302  {
7303  return length == str.size();
7304  }
7305  };
7306 
7307  template <std::size_t length>
7309  {
7310  template <typename Iterator>
7311  inline bool operator()(const Iterator begin, const Iterator end) const
7312  {
7313  return std::distance(begin,end) < static_cast<typename std::iterator_traits<Iterator>::difference_type>(length);
7314  }
7315 
7316  template <typename Iterator>
7317  inline bool operator()(const std::pair<Iterator,Iterator>& range) const
7318  {
7319  return std::distance(range.first,range.second) < static_cast<typename std::iterator_traits<Iterator>::difference_type>(length);
7320  }
7321 
7322  template <typename T,
7323  typename Allocator,
7324  template <typename,typename> class Sequence>
7325  inline bool operator()(const Sequence<T,Allocator>& sequence) const
7326  {
7327  return sequence.size() < length;
7328  }
7329 
7330  template <typename T,
7331  typename Comparator,
7332  typename Allocator>
7333  inline bool operator()(const std::set<T,Comparator,Allocator>& set) const
7334  {
7335  return set.size() < length;
7336  }
7337 
7338  template <typename T,
7339  typename Comparator,
7340  typename Allocator>
7341  inline bool operator()(const std::multiset<T,Comparator,Allocator>& multiset) const
7342  {
7343  return multiset.size() < length;
7344  }
7345 
7346  inline bool operator()(const std::string& str) const
7347  {
7348  return str.size() < length;
7349  }
7350  };
7351 
7352  template <std::size_t length>
7354  {
7355  template <typename Iterator>
7356  inline bool operator()(const Iterator begin, const Iterator end) const
7357  {
7358  return std::distance(begin,end) > static_cast<typename std::iterator_traits<Iterator>::difference_type>(length);
7359  }
7360 
7361  template <typename Iterator>
7362  inline bool operator()(const std::pair<Iterator,Iterator>& range) const
7363  {
7364  return std::distance(range.first,range.second) > static_cast<typename std::iterator_traits<Iterator>::difference_type>(length);
7365  }
7366 
7367  template <typename T,
7368  typename Allocator,
7369  template <typename,typename> class Sequence>
7370  inline bool operator()(const Sequence<T,Allocator>& sequence) const
7371  {
7372  return sequence.size() > length;
7373  }
7374 
7375  template <typename T,
7376  typename Comparator,
7377  typename Allocator>
7378  inline bool operator()(const std::set<T,Comparator,Allocator>& set) const
7379  {
7380  return set.size() > length;
7381  }
7382 
7383  template <typename T,
7384  typename Comparator,
7385  typename Allocator>
7386  inline bool operator()(const std::multiset<T,Comparator,Allocator>& multiset) const
7387  {
7388  return multiset.size() > length;
7389  }
7390 
7391  inline bool operator()(const std::string& str) const
7392  {
7393  return str.size() > length;
7394  }
7395  };
7396 
7398  {
7399  template <typename Iterator>
7400  inline bool operator()(const Iterator begin, const Iterator end) const
7401  {
7402  return 0 == (std::distance(begin,end) % 2);
7403  }
7404 
7405  template <typename Iterator>
7406  inline bool operator()(const std::pair<Iterator,Iterator>& range) const
7407  {
7408  return 0 == (std::distance(range.first,range.second) % 2);
7409  }
7410 
7411  template <typename T,
7412  typename Allocator,
7413  template <typename,typename> class Sequence>
7414  inline bool operator()(const Sequence<T,Allocator>& sequence) const
7415  {
7416  return 0 == (sequence.size() % 2);
7417  }
7418 
7419  template <typename T,
7420  typename Comparator,
7421  typename Allocator>
7422  inline bool operator()(const std::set<T,Comparator,Allocator>& set) const
7423  {
7424  return 0 == (set.size() % 2);
7425  }
7426 
7427  template <typename T,
7428  typename Comparator,
7429  typename Allocator>
7430  inline bool operator()(const std::multiset<T,Comparator,Allocator>& multiset) const
7431  {
7432  return 0 == (multiset.size() % 2);
7433  }
7434 
7435  inline bool operator()(const std::string& str) const
7436  {
7437  return 0 == (str.size() % 2);
7438  }
7439  };
7440 
7442  {
7443  template <typename Iterator>
7444  inline bool operator()(const Iterator begin, const Iterator end) const
7445  {
7446  return 0 != (std::distance(begin,end) % 2);
7447  }
7448 
7449  template <typename Iterator>
7450  inline bool operator()(const std::pair<Iterator,Iterator>& range) const
7451  {
7452  return 0 != (std::distance(range.first,range.second) % 2);
7453  }
7454 
7455  template <typename T,
7456  typename Allocator,
7457  template <typename,typename> class Sequence>
7458  inline bool operator()(const Sequence<T,Allocator>& sequence) const
7459  {
7460  return 0 != (sequence.size() % 2);
7461  }
7462 
7463  template <typename T,
7464  typename Comparator,
7465  typename Allocator>
7466  inline bool operator()(const std::set<T,Comparator,Allocator>& set) const
7467  {
7468  return 0 != (set.size() % 2);
7469  }
7470 
7471  template <typename T,
7472  typename Comparator,
7473  typename Allocator>
7474  inline bool operator()(const std::multiset<T,Comparator,Allocator>& multiset) const
7475  {
7476  return 0 != (multiset.size() % 2);
7477  }
7478 
7479  inline bool operator()(const std::string& str) const
7480  {
7481  return 0 != (str.size() % 2);
7482  }
7483  };
7484 
7485  template <typename InputIterator,
7486  typename T1, typename T2, typename T3, typename T4,
7487  typename T5, typename T6, typename T7, typename T8,
7488  typename T9, typename T10, typename T11, typename T12>
7489  inline bool parse(const InputIterator begin,
7490  const InputIterator end,
7491  const std::string& delimiters,
7492  T1& t1, T2& t2, T3& t3, T4& t4,
7493  T5& t5, T6& t6, T7& t7, T8& t8,
7494  T9& t9, T10& t10, T11& t11, T12& t12)
7495  {
7496  typedef typename details::is_valid_iterator<InputIterator>::type itr_type;
7497  static const std::size_t token_count = 12;
7498  typedef std::pair<InputIterator,InputIterator> iterator_type;
7499  typedef iterator_type* iterator_type_ptr;
7500  iterator_type token_list[token_count];
7501  const std::size_t parsed_token_count = split_n(delimiters,
7502  begin,end,
7503  token_count,
7504  token_list,
7506  if (token_count > parsed_token_count)
7507  return false;
7508  iterator_type_ptr itr = token_list;
7509  if (!string_to_type_converter((*itr).first,(*itr).second, t1)) return false; ++itr;
7510  if (!string_to_type_converter((*itr).first,(*itr).second, t2)) return false; ++itr;
7511  if (!string_to_type_converter((*itr).first,(*itr).second, t3)) return false; ++itr;
7512  if (!string_to_type_converter((*itr).first,(*itr).second, t4)) return false; ++itr;
7513  if (!string_to_type_converter((*itr).first,(*itr).second, t5)) return false; ++itr;
7514  if (!string_to_type_converter((*itr).first,(*itr).second, t6)) return false; ++itr;
7515  if (!string_to_type_converter((*itr).first,(*itr).second, t7)) return false; ++itr;
7516  if (!string_to_type_converter((*itr).first,(*itr).second, t8)) return false; ++itr;
7517  if (!string_to_type_converter((*itr).first,(*itr).second, t9)) return false; ++itr;
7518  if (!string_to_type_converter((*itr).first,(*itr).second,t10)) return false; ++itr;
7519  if (!string_to_type_converter((*itr).first,(*itr).second,t11)) return false; ++itr;
7520  if (!string_to_type_converter((*itr).first,(*itr).second,t12)) return false;
7521  return true;
7522  }
7523 
7524  template <typename InputIterator,
7525  typename T1, typename T2, typename T3, typename T4,
7526  typename T5, typename T6, typename T7, typename T8,
7527  typename T9, typename T10, typename T11>
7528  inline bool parse(const InputIterator begin,
7529  const InputIterator end,
7530  const std::string& delimiters,
7531  T1& t1, T2& t2, T3& t3, T4& t4,
7532  T5& t5, T6& t6, T7& t7, T8& t8,
7533  T9& t9, T10& t10, T11& t11)
7534  {
7535  typedef typename details::is_valid_iterator<InputIterator>::type itr_type;
7536  static const std::size_t token_count = 11;
7537  typedef std::pair<InputIterator,InputIterator> iterator_type;
7538  typedef iterator_type* iterator_type_ptr;
7539  iterator_type token_list[token_count];
7540  const std::size_t parsed_token_count = split_n(delimiters,
7541  begin,end,
7542  token_count,
7543  token_list,
7545  if (token_count > parsed_token_count)
7546  return false;
7547  iterator_type_ptr itr = token_list;
7548  if (!string_to_type_converter((*itr).first,(*itr).second, t1)) return false; ++itr;
7549  if (!string_to_type_converter((*itr).first,(*itr).second, t2)) return false; ++itr;
7550  if (!string_to_type_converter((*itr).first,(*itr).second, t3)) return false; ++itr;
7551  if (!string_to_type_converter((*itr).first,(*itr).second, t4)) return false; ++itr;
7552  if (!string_to_type_converter((*itr).first,(*itr).second, t5)) return false; ++itr;
7553  if (!string_to_type_converter((*itr).first,(*itr).second, t6)) return false; ++itr;
7554  if (!string_to_type_converter((*itr).first,(*itr).second, t7)) return false; ++itr;
7555  if (!string_to_type_converter((*itr).first,(*itr).second, t8)) return false; ++itr;
7556  if (!string_to_type_converter((*itr).first,(*itr).second, t9)) return false; ++itr;
7557  if (!string_to_type_converter((*itr).first,(*itr).second,t10)) return false; ++itr;
7558  if (!string_to_type_converter((*itr).first,(*itr).second,t11)) return false;
7559  return true;
7560  }
7561 
7562  template <typename InputIterator,
7563  typename T1, typename T2, typename T3, typename T4,
7564  typename T5, typename T6, typename T7, typename T8,
7565  typename T9, typename T10>
7566  inline bool parse(const InputIterator begin,
7567  const InputIterator end,
7568  const std::string& delimiters,
7569  T1& t1, T2& t2, T3& t3, T4& t4,
7570  T5& t5, T6& t6, T7& t7, T8& t8,
7571  T9& t9, T10& t10)
7572  {
7573  typedef typename details::is_valid_iterator<InputIterator>::type itr_type;
7574  static const std::size_t token_count = 10;
7575  typedef std::pair<InputIterator,InputIterator> iterator_type;
7576  typedef iterator_type* iterator_type_ptr;
7577  iterator_type token_list[token_count];
7578  const std::size_t parsed_token_count = split_n(delimiters,
7579  begin,end,
7580  token_count,
7581  token_list,
7583  if (token_count > parsed_token_count)
7584  return false;
7585  iterator_type_ptr itr = token_list;
7586  if (!string_to_type_converter((*itr).first,(*itr).second, t1)) return false; ++itr;
7587  if (!string_to_type_converter((*itr).first,(*itr).second, t2)) return false; ++itr;
7588  if (!string_to_type_converter((*itr).first,(*itr).second, t3)) return false; ++itr;
7589  if (!string_to_type_converter((*itr).first,(*itr).second, t4)) return false; ++itr;
7590  if (!string_to_type_converter((*itr).first,(*itr).second, t5)) return false; ++itr;
7591  if (!string_to_type_converter((*itr).first,(*itr).second, t6)) return false; ++itr;
7592  if (!string_to_type_converter((*itr).first,(*itr).second, t7)) return false; ++itr;
7593  if (!string_to_type_converter((*itr).first,(*itr).second, t8)) return false; ++itr;
7594  if (!string_to_type_converter((*itr).first,(*itr).second, t9)) return false; ++itr;
7595  if (!string_to_type_converter((*itr).first,(*itr).second,t10)) return false;
7596  return true;
7597  }
7598 
7599  template <typename InputIterator,
7600  typename T1, typename T2, typename T3, typename T4,
7601  typename T5, typename T6, typename T7, typename T8,
7602  typename T9>
7603  inline bool parse(const InputIterator begin,
7604  const InputIterator end,
7605  const std::string& delimiters,
7606  T1& t1, T2& t2, T3& t3, T4& t4,
7607  T5& t5, T6& t6, T7& t7, T8& t8,
7608  T9& t9)
7609  {
7610  typedef typename details::is_valid_iterator<InputIterator>::type itr_type;
7611  static const std::size_t token_count = 9;
7612  typedef std::pair<InputIterator,InputIterator> iterator_type;
7613  typedef iterator_type* iterator_type_ptr;
7614  iterator_type token_list[token_count];
7615  const std::size_t parsed_token_count = split_n(delimiters,
7616  begin,end,
7617  token_count,
7618  token_list,
7620  if (token_count > parsed_token_count)
7621  return false;
7622  iterator_type_ptr itr = token_list;
7623  if (!string_to_type_converter((*itr).first,(*itr).second,t1)) return false; ++itr;
7624  if (!string_to_type_converter((*itr).first,(*itr).second,t2)) return false; ++itr;
7625  if (!string_to_type_converter((*itr).first,(*itr).second,t3)) return false; ++itr;
7626  if (!string_to_type_converter((*itr).first,(*itr).second,t4)) return false; ++itr;
7627  if (!string_to_type_converter((*itr).first,(*itr).second,t5)) return false; ++itr;
7628  if (!string_to_type_converter((*itr).first,(*itr).second,t6)) return false; ++itr;
7629  if (!string_to_type_converter((*itr).first,(*itr).second,t7)) return false; ++itr;
7630  if (!string_to_type_converter((*itr).first,(*itr).second,t8)) return false; ++itr;
7631  if (!string_to_type_converter((*itr).first,(*itr).second,t9)) return false;
7632  return true;
7633  }
7634 
7635  template <typename InputIterator,
7636  typename T1, typename T2, typename T3, typename T4,
7637  typename T5, typename T6, typename T7, typename T8>
7638  inline bool parse(const InputIterator begin,
7639  const InputIterator end,
7640  const std::string& delimiters,
7641  T1& t1, T2& t2, T3& t3, T4& t4,
7642  T5& t5, T6& t6, T7& t7, T8& t8)
7643  {
7644  typedef typename details::is_valid_iterator<InputIterator>::type itr_type;
7645  static const std::size_t token_count = 8;
7646  typedef std::pair<InputIterator,InputIterator> iterator_type;
7647  typedef iterator_type* iterator_type_ptr;
7648  iterator_type token_list[token_count];
7649  const std::size_t parsed_token_count = split_n(delimiters,
7650  begin,end,
7651  token_count,
7652  token_list,
7654  if (token_count > parsed_token_count)
7655  return false;
7656  iterator_type_ptr itr = token_list;
7657  if (!string_to_type_converter((*itr).first,(*itr).second,t1)) return false; ++itr;
7658  if (!string_to_type_converter((*itr).first,(*itr).second,t2)) return false; ++itr;
7659  if (!string_to_type_converter((*itr).first,(*itr).second,t3)) return false; ++itr;
7660  if (!string_to_type_converter((*itr).first,(*itr).second,t4)) return false; ++itr;
7661  if (!string_to_type_converter((*itr).first,(*itr).second,t5)) return false; ++itr;
7662  if (!string_to_type_converter((*itr).first,(*itr).second,t6)) return false; ++itr;
7663  if (!string_to_type_converter((*itr).first,(*itr).second,t7)) return false; ++itr;
7664  if (!string_to_type_converter((*itr).first,(*itr).second,t8)) return false;
7665  return true;
7666  }
7667 
7668  template <typename InputIterator,
7669  typename T1, typename T2, typename T3, typename T4,
7670  typename T5, typename T6, typename T7>
7671  inline bool parse(const InputIterator begin,
7672  const InputIterator end,
7673  const std::string& delimiters,
7674  T1& t1, T2& t2, T3& t3, T4& t4,
7675  T5& t5, T6& t6, T7& t7)
7676  {
7677  typedef typename details::is_valid_iterator<InputIterator>::type itr_type;
7678  static const std::size_t token_count = 7;
7679  typedef std::pair<InputIterator,InputIterator> iterator_type;
7680  typedef iterator_type* iterator_type_ptr;
7681  iterator_type token_list[token_count];
7682  const std::size_t parsed_token_count = split_n(delimiters,
7683  begin,end,
7684  token_count,
7685  token_list,
7687  if (token_count > parsed_token_count)
7688  return false;
7689  iterator_type_ptr itr = token_list;
7690  if (!string_to_type_converter((*itr).first,(*itr).second,t1)) return false; ++itr;
7691  if (!string_to_type_converter((*itr).first,(*itr).second,t2)) return false; ++itr;
7692  if (!string_to_type_converter((*itr).first,(*itr).second,t3)) return false; ++itr;
7693  if (!string_to_type_converter((*itr).first,(*itr).second,t4)) return false; ++itr;
7694  if (!string_to_type_converter((*itr).first,(*itr).second,t5)) return false; ++itr;
7695  if (!string_to_type_converter((*itr).first,(*itr).second,t6)) return false; ++itr;
7696  if (!string_to_type_converter((*itr).first,(*itr).second,t7)) return false;
7697  return true;
7698  }
7699 
7700  template <typename InputIterator,
7701  typename T1, typename T2, typename T3, typename T4,
7702  typename T5, typename T6>
7703  inline bool parse(const InputIterator begin,
7704  const InputIterator end,
7705  const std::string& delimiters,
7706  T1& t1, T2& t2, T3& t3, T4& t4,
7707  T5& t5, T6& t6)
7708  {
7709  typedef typename details::is_valid_iterator<InputIterator>::type itr_type;
7710  static const std::size_t token_count = 6;
7711  typedef std::pair<InputIterator,InputIterator> iterator_type;
7712  typedef iterator_type* iterator_type_ptr;
7713  iterator_type token_list[token_count];
7714  const std::size_t parsed_token_count = split_n(delimiters,
7715  begin,end,
7716  token_count,
7717  token_list,
7719  if (token_count > parsed_token_count)
7720  return false;
7721  iterator_type_ptr itr = token_list;
7722  if (!string_to_type_converter((*itr).first,(*itr).second,t1)) return false; ++itr;
7723  if (!string_to_type_converter((*itr).first,(*itr).second,t2)) return false; ++itr;
7724  if (!string_to_type_converter((*itr).first,(*itr).second,t3)) return false; ++itr;
7725  if (!string_to_type_converter((*itr).first,(*itr).second,t4)) return false; ++itr;
7726  if (!string_to_type_converter((*itr).first,(*itr).second,t5)) return false; ++itr;
7727  if (!string_to_type_converter((*itr).first,(*itr).second,t6)) return false;
7728  return true;
7729  }
7730 
7731  template <typename InputIterator,
7732  typename T1, typename T2, typename T3, typename T4,
7733  typename T5>
7734  inline bool parse(const InputIterator begin,
7735  const InputIterator end,
7736  const std::string& delimiters,
7737  T1& t1, T2& t2, T3& t3, T4& t4,
7738  T5& t5)
7739  {
7740  typedef typename details::is_valid_iterator<InputIterator>::type itr_type;
7741  static const std::size_t token_count = 5;
7742  typedef std::pair<InputIterator,InputIterator> iterator_type;
7743  typedef iterator_type* iterator_type_ptr;
7744  iterator_type token_list[token_count];
7745  const std::size_t parsed_token_count = split_n(delimiters,
7746  begin,end,
7747  token_count,
7748  token_list,
7750  if (token_count > parsed_token_count)
7751  return false;
7752  iterator_type_ptr itr = token_list;
7753  if (!string_to_type_converter((*itr).first,(*itr).second,t1)) return false; ++itr;
7754  if (!string_to_type_converter((*itr).first,(*itr).second,t2)) return false; ++itr;
7755  if (!string_to_type_converter((*itr).first,(*itr).second,t3)) return false; ++itr;
7756  if (!string_to_type_converter((*itr).first,(*itr).second,t4)) return false; ++itr;
7757  if (!string_to_type_converter((*itr).first,(*itr).second,t5)) return false;
7758  return true;
7759  }
7760 
7761  template <typename InputIterator,
7762  typename T1, typename T2, typename T3, typename T4>
7763  inline bool parse(const InputIterator begin,
7764  const InputIterator end,
7765  const std::string& delimiters,
7766  T1& t1, T2& t2, T3& t3, T4& t4)
7767  {
7768  typedef typename details::is_valid_iterator<InputIterator>::type itr_type;
7769  static const std::size_t token_count = 4;
7770  typedef std::pair<InputIterator,InputIterator> iterator_type;
7771  typedef iterator_type* iterator_type_ptr;
7772  iterator_type token_list[token_count];
7773  const std::size_t parsed_token_count = split_n(delimiters,
7774  begin,end,
7775  token_count,
7776  token_list,
7778  if (token_count > parsed_token_count)
7779  return false;
7780  iterator_type_ptr itr = token_list;
7781  if (!string_to_type_converter((*itr).first,(*itr).second,t1)) return false; ++itr;
7782  if (!string_to_type_converter((*itr).first,(*itr).second,t2)) return false; ++itr;
7783  if (!string_to_type_converter((*itr).first,(*itr).second,t3)) return false; ++itr;
7784  if (!string_to_type_converter((*itr).first,(*itr).second,t4)) return false;
7785  return true;
7786  }
7787 
7788  template <typename InputIterator,
7789  typename T1, typename T2, typename T3>
7790  inline bool parse(const InputIterator begin,
7791  const InputIterator end,
7792  const std::string& delimiters,
7793  T1& t1, T2& t2, T3& t3)
7794  {
7795  typedef typename details::is_valid_iterator<InputIterator>::type itr_type;
7796  static const std::size_t token_count = 3;
7797  typedef std::pair<InputIterator,InputIterator> iterator_type;
7798  typedef iterator_type* iterator_type_ptr;
7799  iterator_type token_list[token_count];
7800  const std::size_t parsed_token_count = split_n(delimiters,
7801  begin,end,
7802  token_count,
7803  token_list,
7805  if (token_count > parsed_token_count)
7806  return false;
7807  iterator_type_ptr itr = token_list;
7808  if (!string_to_type_converter((*itr).first,(*itr).second,t1)) return false; ++itr;
7809  if (!string_to_type_converter((*itr).first,(*itr).second,t2)) return false; ++itr;
7810  if (!string_to_type_converter((*itr).first,(*itr).second,t3)) return false;
7811  return true;
7812  }
7813 
7814  template <typename InputIterator, typename T1, typename T2>
7815  inline bool parse(const InputIterator begin,
7816  const InputIterator end,
7817  const std::string& delimiters,
7818  T1& t1, T2& t2)
7819  {
7820  typedef typename details::is_valid_iterator<InputIterator>::type itr_type;
7821  static const std::size_t token_count = 2;
7822  typedef std::pair<InputIterator,InputIterator> iterator_type;
7823  typedef iterator_type* iterator_type_ptr;
7824  iterator_type token_list[token_count];
7825  const std::size_t parsed_token_count = split_n(delimiters,
7826  begin,end,
7827  token_count,
7828  token_list,
7830  if (token_count > parsed_token_count)
7831  return false;
7832  iterator_type_ptr itr = token_list;
7833  if (!string_to_type_converter((*itr).first,(*itr).second,t1)) return false; ++itr;
7834  if (!string_to_type_converter((*itr).first,(*itr).second,t2)) return false;
7835  return true;
7836  }
7837 
7838  template <typename InputIterator, typename T>
7839  inline bool parse(const InputIterator begin,
7840  const InputIterator end,
7841  const std::string& delimiters,
7842  T& t)
7843  {
7844  typedef typename details::is_valid_iterator<InputIterator>::type itr_type;
7845  static const std::size_t token_count = 1;
7846  typedef std::pair<InputIterator,InputIterator> iterator_type;
7847  typedef iterator_type* iterator_type_ptr;
7848  iterator_type token_list[token_count];
7849  const std::size_t parsed_token_count = split_n(delimiters,
7850  begin,end,
7851  token_count,
7852  token_list,
7854  if (token_count > parsed_token_count)
7855  return false;
7856  iterator_type_ptr itr = token_list;
7857  return string_to_type_converter((*itr).first,(*itr).second,t);
7858  }
7859 
7860  template <typename InputIterator,
7861  typename T,
7862  typename Allocator,
7863  template <typename,typename> class Sequence>
7864  inline std::size_t parse(const InputIterator begin,
7865  const InputIterator end,
7866  const std::string& delimiters,
7867  Sequence<T,Allocator>& sequence,
7869  {
7870  typedef typename details::is_valid_iterator<InputIterator>::type itr_type;
7871  if (1 == delimiters.size())
7873  begin,end,
7874  range_to_type_back_inserter(sequence),
7875  split_option);
7876  else
7877  return split(multiple_char_delimiter_predicate(delimiters),
7878  begin, end,
7879  range_to_type_back_inserter(sequence),
7880  split_option);
7881  }
7882 
7883  template <typename InputIterator,
7884  typename T,
7885  typename Comparator,
7886  typename Allocator>
7887  inline std::size_t parse(const InputIterator begin,
7888  const InputIterator end,
7889  const std::string& delimiters,
7890  std::set<T,Comparator,Allocator>& set,
7892  {
7893  typedef typename details::is_valid_iterator<InputIterator>::type itr_type;
7894  if (1 == delimiters.size())
7896  begin,end,
7898  split_option);
7899  else
7900  return split(multiple_char_delimiter_predicate(delimiters),
7901  begin,end,
7903  split_option);
7904  }
7905 
7906  template <typename InputIterator,
7907  typename T,
7908  typename Comparator,
7909  typename Allocator>
7910  inline std::size_t parse(const InputIterator begin,
7911  const InputIterator end,
7912  const std::string& delimiters,
7913  std::multiset<T,Comparator,Allocator>& multiset,
7915  {
7916  typedef typename details::is_valid_iterator<InputIterator>::type itr_type;
7917  if (1 == delimiters.size())
7919  begin,end,
7920  range_to_type_inserter(multiset),
7921  split_option);
7922  else
7923  return split(multiple_char_delimiter_predicate(delimiters),
7924  begin,end,
7925  range_to_type_inserter(multiset),
7926  split_option);
7927  }
7928 
7929  template <typename InputIterator,
7930  typename T,
7931  typename Container>
7932  inline std::size_t parse(const InputIterator begin,
7933  const InputIterator end,
7934  const std::string& delimiters,
7935  std::queue<T,Container>& queue,
7937  {
7938  typedef typename details::is_valid_iterator<InputIterator>::type itr_type;
7939  if (1 == delimiters.size())
7941  begin,end,
7943  split_option);
7944  else
7945  return split(multiple_char_delimiter_predicate(delimiters),
7946  begin,end,
7948  split_option);
7949  }
7950 
7951  template <typename InputIterator,
7952  typename T,
7953  typename Container>
7954  inline std::size_t parse(const InputIterator begin,
7955  const InputIterator end,
7956  const std::string& delimiters,
7957  std::stack<T,Container>& stack,
7959  {
7960  typedef typename details::is_valid_iterator<InputIterator>::type itr_type;
7961  if (1 == delimiters.size())
7963  begin,end,
7965  split_option);
7966  else
7967  return split(multiple_char_delimiter_predicate(delimiters),
7968  begin, end,
7970  split_option);
7971  }
7972 
7973  template <typename InputIterator,
7974  typename T,
7975  typename Container,
7976  typename Comparator>
7977  inline std::size_t parse(const InputIterator begin,
7978  const InputIterator end,
7979  const std::string& delimiters,
7980  std::priority_queue<T,Container,Comparator>& priority_queue,
7982  {
7983  typedef typename details::is_valid_iterator<InputIterator>::type itr_type;
7984  if (1 == delimiters.size())
7986  begin,end,
7987  range_to_type_push_inserter(priority_queue),
7988  split_option);
7989  else
7990  return split(multiple_char_delimiter_predicate(delimiters),
7991  begin,end,
7992  range_to_type_push_inserter(priority_queue),
7993  split_option);
7994  }
7995 
7996  template <typename InputIterator,
7997  typename T,
7998  typename Allocator,
7999  template <typename,typename> class Sequence>
8000  inline std::size_t parse(const std::pair<InputIterator,InputIterator>& range,
8001  const std::string& delimiters,
8002  Sequence<T,Allocator>& sequence,
8004  {
8005  typedef typename details::is_valid_iterator<InputIterator>::type itr_type;
8006  if (1 == delimiters.size())
8008  range.first,range.second,
8009  range_to_type_back_inserter(sequence),
8010  split_option);
8011  else
8012  return split(multiple_char_delimiter_predicate(delimiters),
8013  range.first,range.second,
8014  range_to_type_back_inserter(sequence),
8015  split_option);
8016  }
8017 
8018  template <typename InputIterator,
8019  typename T,
8020  typename Comparator,
8021  typename Allocator>
8022  inline std::size_t parse(const std::pair<InputIterator,InputIterator>& range,
8023  const std::string& delimiters,
8024  std::set<T,Comparator,Allocator>& set,
8026  {
8027  typedef typename details::is_valid_iterator<InputIterator>::type itr_type;
8028  if (1 == delimiters.size())
8030  range.first,range.second,
8032  split_option);
8033  else
8034  return split(multiple_char_delimiter_predicate(delimiters),
8035  range.first,range.second,
8037  split_option);
8038  }
8039 
8040  template <typename InputIterator,
8041  typename T,
8042  typename Comparator,
8043  typename Allocator>
8044  inline std::size_t parse(const std::pair<InputIterator,InputIterator>& range,
8045  const std::string& delimiters,
8046  std::multiset<T,Comparator,Allocator>& multiset,
8048  {
8049  typedef typename details::is_valid_iterator<InputIterator>::type itr_type;
8050  if (1 == delimiters.size())
8052  range.first,range.second,
8053  range_to_type_inserter(multiset),
8054  split_option);
8055  else
8056  return split(multiple_char_delimiter_predicate(delimiters),
8057  range.first,range.second,
8058  range_to_type_inserter(multiset),
8059  split_option);
8060  }
8061 
8062  template <typename InputIterator,
8063  typename T,
8064  typename Container>
8065  inline std::size_t parse(const std::pair<InputIterator,InputIterator>& range,
8066  const std::string& delimiters,
8067  std::queue<T,Container>& queue,
8069  {
8070  typedef typename details::is_valid_iterator<InputIterator>::type itr_type;
8071  if (1 == delimiters.size())
8073  range.first,range.second,
8075  split_option);
8076  else
8077  return split(multiple_char_delimiter_predicate(delimiters),
8078  range.first,range.second,
8080  split_option);
8081  }
8082 
8083  template <typename InputIterator,
8084  typename T,
8085  typename Container>
8086  inline std::size_t parse(const std::pair<InputIterator,InputIterator>& range,
8087  const std::string& delimiters,
8088  std::stack<T,Container>& stack,
8090  {
8091  typedef typename details::is_valid_iterator<InputIterator>::type itr_type;
8092  if (1 == delimiters.size())
8094  range.first,range.second,
8096  split_option);
8097  else
8098  return split(multiple_char_delimiter_predicate(delimiters),
8099  range.first,range.second,
8101  split_option);
8102  }
8103 
8104  template <typename InputIterator,
8105  typename T,
8106  typename Container,
8107  typename Comparator>
8108  inline std::size_t parse(const std::pair<InputIterator,InputIterator>& range,
8109  const std::string& delimiters,
8110  std::priority_queue<T,Container,Comparator>& priority_queue,
8112  {
8113  typedef typename details::is_valid_iterator<InputIterator>::type itr_type;
8114  if (1 == delimiters.size())
8116  range.first,range.second,
8117  range_to_type_push_inserter(priority_queue),
8118  split_option);
8119  else
8120  return split(multiple_char_delimiter_predicate(delimiters),
8121  range.first,range.second,
8122  range_to_type_push_inserter(priority_queue),
8123  split_option);
8124  }
8125 
8126  namespace details
8127  {
8129  {
8130  private:
8131 
8132  class container_adder_base
8133  {
8134  public:
8135 
8136  typedef const char* itr_type;
8137 
8138  virtual ~container_adder_base(){}
8139 
8140  template <typename InputIterator>
8141  inline bool add(const InputIterator begin, const InputIterator end) const
8142  {
8143  return add_impl(begin,end);
8144  }
8145 
8146  template <typename InputIterator>
8147  inline bool add(const std::pair<InputIterator,InputIterator>& range) const
8148  {
8149  return add(range.first,range.second);
8150  }
8151 
8152  protected:
8153 
8154  virtual bool add_impl(const itr_type begin, const itr_type end) const = 0;
8155 
8156  };
8157 
8158  template <typename T,
8159  typename Allocator,
8160  template <typename,typename> class Sequence>
8161  class sequence_adder_impl : public container_adder_base
8162  {
8163  public:
8164 
8165  typedef Sequence<T,Allocator> sequence_t;
8166 
8167  sequence_adder_impl(sequence_t& seq)
8168  : sequence_(seq)
8169  {}
8170 
8171  protected:
8172 
8173  bool add_impl(const itr_type begin, const itr_type end) const
8174  {
8175  T t;
8176  if (!string_to_type_converter(begin,end,t)) return false;
8177  sequence_.push_back(t);
8178  return true;
8179  }
8180 
8181  private:
8182 
8183  sequence_adder_impl operator=(const sequence_adder_impl&);
8184 
8185  sequence_t& sequence_;
8186  };
8187 
8188  template <typename T,
8189  typename Comparator,
8190  typename Allocator,
8191  template <typename,typename,typename> class Set>
8192  class set_adder_impl : public container_adder_base
8193  {
8194  public:
8195 
8196  set_adder_impl(Set<T,Comparator,Allocator>& set)
8197  : set_(set)
8198  {}
8199 
8200  bool add_impl(const itr_type begin, const itr_type end) const
8201  {
8202  T t;
8203  if (!string_to_type_converter(begin,end,t)) return false;
8204  set_.insert(t);
8205  return true;
8206  }
8207 
8208  private:
8209 
8210  set_adder_impl operator=(const set_adder_impl&);
8211 
8212  Set<T,Comparator,Allocator>& set_;
8213  };
8214 
8215  template <typename T,
8216  typename Container,
8217  typename Comparator>
8218  class pq_adder_impl : public container_adder_base
8219  {
8220  public:
8221 
8222  pq_adder_impl(std::priority_queue<T,Container,Comparator>& pq)
8223  : pq_(pq)
8224  {}
8225 
8226  bool add_impl(const itr_type begin, const itr_type end) const
8227  {
8228  T t;
8229  if (!string_to_type_converter(begin,end,t)) return false;
8230  pq_.push(t);
8231  return true;
8232  }
8233 
8234  private:
8235 
8236  pq_adder_impl operator=(const pq_adder_impl&);
8237 
8238  std::priority_queue<T,Container,Comparator>& pq_;
8239  };
8240 
8241  template <typename T,
8242  typename Container,
8243  template <typename,typename> class SContainer>
8244  class stack_queue_adder_impl : public container_adder_base
8245  {
8246  public:
8247 
8248  stack_queue_adder_impl(SContainer<T,Container>& container)
8249  : container_(container)
8250  {}
8251 
8252  bool add_impl(const itr_type begin, const itr_type end) const
8253  {
8254  T t;
8255  if (!string_to_type_converter(begin,end,t)) return false;
8256  container_.push(t);
8257  return true;
8258  }
8259 
8260  private:
8261 
8262  stack_queue_adder_impl operator=(const stack_queue_adder_impl&);
8263 
8264  SContainer<T,Container>& container_;
8265  };
8266 
8267  public:
8268 
8269  template <typename T, typename Allocator>
8270  container_adder(std::vector<T,Allocator>& vec)
8271  : container_adder_base_(new(buffer)sequence_adder_impl<T,Allocator,std::vector>(vec))
8272  {}
8273 
8274  template <typename T, typename Allocator>
8275  container_adder(std::deque<T,Allocator>& deq)
8276  : container_adder_base_(new(buffer)sequence_adder_impl<T,Allocator,std::deque>(deq))
8277  {}
8278 
8279  template <typename T, typename Allocator>
8280  container_adder(std::list<T,Allocator>& list)
8281  : container_adder_base_(new(buffer)sequence_adder_impl<T,Allocator,std::list>(list))
8282  {}
8283 
8284  template <typename T, typename Comparator, typename Allocator>
8285  container_adder(std::set<T,Comparator,Allocator>& set)
8286  : container_adder_base_(new(buffer)set_adder_impl<T,Comparator,Allocator,std::set>(set))
8287  {}
8288 
8289  template <typename T, typename Comparator, typename Allocator>
8290  container_adder(std::multiset<T,Comparator,Allocator>& multiset)
8291  : container_adder_base_(new(buffer)set_adder_impl<T,Comparator,Allocator,std::multiset>(multiset))
8292  {}
8293 
8294  template <typename T, typename Container, typename Comparator>
8295  container_adder(std::priority_queue<T,Container,Comparator>& pq)
8296  : container_adder_base_(new(buffer)pq_adder_impl<T,Container,Comparator>(pq))
8297  {}
8298 
8299  template <typename T, typename Container>
8300  container_adder(std::queue<T,Container>& queue)
8301  : container_adder_base_(new(buffer)stack_queue_adder_impl<T,Container,std::queue>(queue))
8302  {}
8303 
8304  template <typename T, typename Container>
8305  container_adder(std::stack<T,Container>& stack)
8306  : container_adder_base_(new(buffer)stack_queue_adder_impl<T,Container,std::stack>(stack))
8307  {}
8308 
8309  template <typename InputIterator>
8310  inline bool add(InputIterator begin, InputIterator end) const
8311  {
8312  return container_adder_base_->add(begin,end);
8313  }
8314 
8315  template <typename InputIterator>
8316  inline bool add(std::pair<InputIterator,InputIterator>& range) const
8317  {
8318  return add(range.first,range.second);
8319  }
8320 
8321  template <typename InputIterator>
8322  inline bool operator()(const InputIterator begin, const InputIterator end)
8323  {
8324  InputIterator itr = begin;
8325  while (end != itr)
8326  {
8327  if (!add(*itr)) return false;
8328  ++itr;
8329  }
8330  return true;
8331  }
8332 
8333  private:
8334 
8335  mutable container_adder_base* container_adder_base_;
8336  unsigned char buffer[64];
8337  };
8338 
8339  template <typename T,typename is_stl_container_result>
8340  struct ca_type { typedef T& type; };
8341 
8342  template <typename T>
8343  struct ca_type <T,details::yes_t> { typedef details::container_adder type; };
8344 
8345  }
8346 
8347  template <typename InputIterator,
8348  typename T1, typename T2, typename T3,
8349  typename T4, typename T5, typename T6,
8350  typename T7, typename T8, typename T9,
8351  typename T10, typename T11>
8352  inline bool parse(const InputIterator begin, const InputIterator end,
8353  const std::string& delimiters,
8354  T1& t1, T2& t2, T3& t3, T4& t4, T5& t5, T6& t6, T7& t7,
8355  T8& t8, T9& t9, T10& t10, T11& t11,
8357  {
8358  typedef typename details::is_valid_iterator<InputIterator>::type itr_type;
8359  typedef std::pair<InputIterator,InputIterator> iterator_type;
8360  typedef typename std::deque<iterator_type>::iterator iterator_type_ptr;
8361  std::deque<iterator_type> token_list;
8362  if (1 == delimiters.size())
8364  begin,end,
8365  std::back_inserter(token_list),
8367  else
8369  begin,end,
8370  std::back_inserter(token_list),
8372  if (token_list.size() < 12) return false;
8373  iterator_type_ptr itr = token_list.begin();
8374  if (!string_to_type_converter((*itr).first,(*itr).second, t1)) return false; ++itr;
8375  if (!string_to_type_converter((*itr).first,(*itr).second, t2)) return false; ++itr;
8376  if (!string_to_type_converter((*itr).first,(*itr).second, t3)) return false; ++itr;
8377  if (!string_to_type_converter((*itr).first,(*itr).second, t4)) return false; ++itr;
8378  if (!string_to_type_converter((*itr).first,(*itr).second, t5)) return false; ++itr;
8379  if (!string_to_type_converter((*itr).first,(*itr).second, t6)) return false; ++itr;
8380  if (!string_to_type_converter((*itr).first,(*itr).second, t7)) return false; ++itr;
8381  if (!string_to_type_converter((*itr).first,(*itr).second, t8)) return false; ++itr;
8382  if (!string_to_type_converter((*itr).first,(*itr).second, t9)) return false; ++itr;
8383  if (!string_to_type_converter((*itr).first,(*itr).second,t10)) return false; ++itr;
8384  if (!string_to_type_converter((*itr).first,(*itr).second,t11)) return false; ++itr;
8385  return ca(itr,token_list.end());
8386  }
8387 
8388  template <typename InputIterator,
8389  typename T1, typename T2, typename T3,
8390  typename T4, typename T5, typename T6,
8391  typename T7, typename T8, typename T9,
8392  typename T10>
8393  inline bool parse(const InputIterator begin, const InputIterator end,
8394  const std::string& delimiters,
8395  T1& t1, T2& t2, T3& t3, T4& t4, T5& t5, T6& t6, T7& t7, T8& t8, T9& t9, T10& t10,
8397  {
8398  typedef typename details::is_valid_iterator<InputIterator>::type itr_type;
8399  typedef std::pair<InputIterator,InputIterator> iterator_type;
8400  typedef typename std::deque<iterator_type>::iterator iterator_type_ptr;
8401  std::deque<iterator_type> token_list;
8402  if (1 == delimiters.size())
8404  begin,end,
8405  std::back_inserter(token_list),
8407  else
8409  begin,end,
8410  std::back_inserter(token_list),
8412  if (token_list.size() < 11) return false;
8413  iterator_type_ptr itr = token_list.begin();
8414  if (!string_to_type_converter((*itr).first,(*itr).second, t1)) return false; ++itr;
8415  if (!string_to_type_converter((*itr).first,(*itr).second, t2)) return false; ++itr;
8416  if (!string_to_type_converter((*itr).first,(*itr).second, t3)) return false; ++itr;
8417  if (!string_to_type_converter((*itr).first,(*itr).second, t4)) return false; ++itr;
8418  if (!string_to_type_converter((*itr).first,(*itr).second, t5)) return false; ++itr;
8419  if (!string_to_type_converter((*itr).first,(*itr).second, t6)) return false; ++itr;
8420  if (!string_to_type_converter((*itr).first,(*itr).second, t7)) return false; ++itr;
8421  if (!string_to_type_converter((*itr).first,(*itr).second, t8)) return false; ++itr;
8422  if (!string_to_type_converter((*itr).first,(*itr).second, t9)) return false; ++itr;
8423  if (!string_to_type_converter((*itr).first,(*itr).second,t10)) return false; ++itr;
8424  return ca(itr,token_list.end());
8425  }
8426 
8427  template <typename InputIterator,
8428  typename T1, typename T2, typename T3,
8429  typename T4, typename T5, typename T6,
8430  typename T7, typename T8, typename T9>
8431  inline bool parse(const InputIterator begin, const InputIterator end,
8432  const std::string& delimiters,
8433  T1& t1, T2& t2, T3& t3, T4& t4, T5& t5, T6& t6, T7& t7, T8& t8, T9& t9,
8435  {
8436  typedef typename details::is_valid_iterator<InputIterator>::type itr_type;
8437  typedef std::pair<InputIterator,InputIterator> iterator_type;
8438  typedef typename std::deque<iterator_type>::iterator iterator_type_ptr;
8439  std::deque<iterator_type> token_list;
8440  if (1 == delimiters.size())
8442  begin,end,
8443  std::back_inserter(token_list),
8445  else
8447  begin,end,
8448  std::back_inserter(token_list),
8450  if (token_list.size() < 10) return false;
8451  iterator_type_ptr itr = token_list.begin();
8452  if (!string_to_type_converter((*itr).first,(*itr).second,t1)) return false; ++itr;
8453  if (!string_to_type_converter((*itr).first,(*itr).second,t2)) return false; ++itr;
8454  if (!string_to_type_converter((*itr).first,(*itr).second,t3)) return false; ++itr;
8455  if (!string_to_type_converter((*itr).first,(*itr).second,t4)) return false; ++itr;
8456  if (!string_to_type_converter((*itr).first,(*itr).second,t5)) return false; ++itr;
8457  if (!string_to_type_converter((*itr).first,(*itr).second,t6)) return false; ++itr;
8458  if (!string_to_type_converter((*itr).first,(*itr).second,t7)) return false; ++itr;
8459  if (!string_to_type_converter((*itr).first,(*itr).second,t8)) return false; ++itr;
8460  if (!string_to_type_converter((*itr).first,(*itr).second,t9)) return false; ++itr;
8461  return ca(itr,token_list.end());
8462  }
8463 
8464  template <typename InputIterator,
8465  typename T1, typename T2, typename T3,
8466  typename T4, typename T5, typename T6,
8467  typename T7, typename T8>
8468  inline bool parse(const InputIterator begin, const InputIterator end,
8469  const std::string& delimiters,
8470  T1& t1, T2& t2, T3& t3, T4& t4, T5& t5, T6& t6, T7& t7, T8& t8,
8472  {
8473  typedef typename details::is_valid_iterator<InputIterator>::type itr_type;
8474  typedef std::pair<InputIterator,InputIterator> iterator_type;
8475  typedef typename std::deque<iterator_type>::iterator iterator_type_ptr;
8476  std::deque<iterator_type> token_list;
8477  if (1 == delimiters.size())
8479  begin,end,
8480  std::back_inserter(token_list),
8482  else
8484  begin,end,
8485  std::back_inserter(token_list),
8487  if (token_list.size() < 9) return false;
8488  iterator_type_ptr itr = token_list.begin();
8489  if (!string_to_type_converter((*itr).first,(*itr).second,t1)) return false; ++itr;
8490  if (!string_to_type_converter((*itr).first,(*itr).second,t2)) return false; ++itr;
8491  if (!string_to_type_converter((*itr).first,(*itr).second,t3)) return false; ++itr;
8492  if (!string_to_type_converter((*itr).first,(*itr).second,t4)) return false; ++itr;
8493  if (!string_to_type_converter((*itr).first,(*itr).second,t5)) return false; ++itr;
8494  if (!string_to_type_converter((*itr).first,(*itr).second,t6)) return false; ++itr;
8495  if (!string_to_type_converter((*itr).first,(*itr).second,t7)) return false; ++itr;
8496  if (!string_to_type_converter((*itr).first,(*itr).second,t8)) return false; ++itr;
8497  return ca(itr,token_list.end());
8498  }
8499 
8500  template <typename InputIterator,
8501  typename T1, typename T2, typename T3,
8502  typename T4, typename T5, typename T6, typename T7>
8503  inline bool parse(const InputIterator begin, const InputIterator end,
8504  const std::string& delimiters,
8505  T1& t1, T2& t2, T3& t3, T4& t4, T5& t5, T6& t6, T7& t7,
8507  {
8508  typedef typename details::is_valid_iterator<InputIterator>::type itr_type;
8509  typedef std::pair<InputIterator,InputIterator> iterator_type;
8510  typedef typename std::deque<iterator_type>::iterator iterator_type_ptr;
8511  std::deque<iterator_type> token_list;
8512  if (1 == delimiters.size())
8514  begin,end,
8515  std::back_inserter(token_list),
8517  else
8519  begin,end,
8520  std::back_inserter(token_list),
8522  if (token_list.size() < 8) return false;
8523  iterator_type_ptr itr = token_list.begin();
8524  if (!string_to_type_converter((*itr).first,(*itr).second,t1)) return false; ++itr;
8525  if (!string_to_type_converter((*itr).first,(*itr).second,t2)) return false; ++itr;
8526  if (!string_to_type_converter((*itr).first,(*itr).second,t3)) return false; ++itr;
8527  if (!string_to_type_converter((*itr).first,(*itr).second,t4)) return false; ++itr;
8528  if (!string_to_type_converter((*itr).first,(*itr).second,t5)) return false; ++itr;
8529  if (!string_to_type_converter((*itr).first,(*itr).second,t6)) return false; ++itr;
8530  if (!string_to_type_converter((*itr).first,(*itr).second,t7)) return false; ++itr;
8531  return ca(itr,token_list.end());
8532  }
8533 
8534  template <typename InputIterator,
8535  typename T1, typename T2, typename T3,
8536  typename T4, typename T5, typename T6>
8537  inline bool parse(const InputIterator begin, const InputIterator end,
8538  const std::string& delimiters,
8539  T1& t1, T2& t2, T3& t3, T4& t4, T5& t5, T6& t6,
8541  {
8542  typedef typename details::is_valid_iterator<InputIterator>::type itr_type;
8543  typedef std::pair<InputIterator,InputIterator> iterator_type;
8544  typedef typename std::deque<iterator_type>::iterator iterator_type_ptr;
8545  std::deque<iterator_type> token_list;
8546  if (1 == delimiters.size())
8548  begin,end,
8549  std::back_inserter(token_list),
8551  else
8553  begin,end,
8554  std::back_inserter(token_list),
8556  if (token_list.size() < 7) return false;
8557  iterator_type_ptr itr = token_list.begin();
8558  if (!string_to_type_converter((*itr).first,(*itr).second,t1)) return false; ++itr;
8559  if (!string_to_type_converter((*itr).first,(*itr).second,t2)) return false; ++itr;
8560  if (!string_to_type_converter((*itr).first,(*itr).second,t3)) return false; ++itr;
8561  if (!string_to_type_converter((*itr).first,(*itr).second,t4)) return false; ++itr;
8562  if (!string_to_type_converter((*itr).first,(*itr).second,t5)) return false; ++itr;
8563  if (!string_to_type_converter((*itr).first,(*itr).second,t6)) return false; ++itr;
8564  return ca(itr,token_list.end());
8565  }
8566 
8567  template <typename InputIterator,
8568  typename T1, typename T2, typename T3,
8569  typename T4, typename T5>
8570  inline bool parse(const InputIterator begin, const InputIterator end,
8571  const std::string& delimiters,
8572  T1& t1, T2& t2, T3& t3, T4& t4, T5& t5,
8574  {
8575  typedef typename details::is_valid_iterator<InputIterator>::type itr_type;
8576  typedef std::pair<InputIterator,InputIterator> iterator_type;
8577  typedef typename std::deque<iterator_type>::iterator iterator_type_ptr;
8578  std::deque<iterator_type> token_list;
8579  if (1 == delimiters.size())
8581  begin,end,
8582  std::back_inserter(token_list),
8584  else
8586  begin,end,
8587  std::back_inserter(token_list),
8589  if (token_list.size() < 6) return false;
8590  iterator_type_ptr itr = token_list.begin();
8591  if (!string_to_type_converter((*itr).first,(*itr).second,t1)) return false; ++itr;
8592  if (!string_to_type_converter((*itr).first,(*itr).second,t2)) return false; ++itr;
8593  if (!string_to_type_converter((*itr).first,(*itr).second,t3)) return false; ++itr;
8594  if (!string_to_type_converter((*itr).first,(*itr).second,t4)) return false; ++itr;
8595  if (!string_to_type_converter((*itr).first,(*itr).second,t5)) return false; ++itr;
8596  return ca(itr,token_list.end());
8597  }
8598 
8599  template <typename InputIterator,
8600  typename T1, typename T2, typename T3, typename T4>
8601  inline bool parse(const InputIterator begin, const InputIterator end,
8602  const std::string& delimiters,
8603  T1& t1, T2& t2, T3& t3, T4& t4,
8605  {
8606  typedef typename details::is_valid_iterator<InputIterator>::type itr_type;
8607  typedef std::pair<InputIterator,InputIterator> iterator_type;
8608  typedef typename std::deque<iterator_type>::iterator iterator_type_ptr;
8609  std::deque<iterator_type> token_list;
8610  if (1 == delimiters.size())
8612  begin,end,
8613  std::back_inserter(token_list),
8615  else
8617  begin,end,
8618  std::back_inserter(token_list),
8620  if (token_list.size() < 5) return false;
8621  iterator_type_ptr itr = token_list.begin();
8622  if (!string_to_type_converter((*itr).first,(*itr).second,t1)) return false; ++itr;
8623  if (!string_to_type_converter((*itr).first,(*itr).second,t2)) return false; ++itr;
8624  if (!string_to_type_converter((*itr).first,(*itr).second,t3)) return false; ++itr;
8625  if (!string_to_type_converter((*itr).first,(*itr).second,t4)) return false; ++itr;
8626  return ca(itr,token_list.end());
8627  }
8628 
8629  template <typename InputIterator,
8630  typename T1, typename T2, typename T3>
8631  inline bool parse(const InputIterator begin, const InputIterator end,
8632  const std::string& delimiters,
8633  T1& t1, T2& t2, T3& t3,
8635  {
8636  typedef typename details::is_valid_iterator<InputIterator>::type itr_type;
8637  typedef std::pair<InputIterator,InputIterator> iterator_type;
8638  typedef typename std::deque<iterator_type>::iterator iterator_type_ptr;
8639  std::deque<iterator_type> token_list;
8640  if (1 == delimiters.size())
8642  begin,end,
8643  std::back_inserter(token_list),
8645  else
8647  begin,end,
8648  std::back_inserter(token_list),
8650  if (token_list.size() < 4) return false;
8651  iterator_type_ptr itr = token_list.begin();
8652  if (!string_to_type_converter((*itr).first,(*itr).second,t1)) return false; ++itr;
8653  if (!string_to_type_converter((*itr).first,(*itr).second,t2)) return false; ++itr;
8654  if (!string_to_type_converter((*itr).first,(*itr).second,t3)) return false; ++itr;
8655  return ca(itr,token_list.end());
8656  }
8657 
8658  template <typename InputIterator,
8659  typename T1, typename T2>
8660  inline bool parse(const InputIterator begin, const InputIterator end,
8661  const std::string& delimiters,
8662  T1& t1, T2& t2,
8664  {
8665  typedef typename details::is_valid_iterator<InputIterator>::type itr_type;
8666  typedef std::pair<InputIterator,InputIterator> iterator_type;
8667  typedef typename std::deque<iterator_type>::iterator iterator_type_ptr;
8668  std::deque<iterator_type> token_list;
8669  if (1 == delimiters.size())
8671  begin,end,
8672  std::back_inserter(token_list),
8674  else
8676  begin,end,
8677  std::back_inserter(token_list),
8679  if (token_list.size() < 3) return false;
8680  iterator_type_ptr itr = token_list.begin();
8681  if (!string_to_type_converter((*itr).first,(*itr).second,t1)) return false; ++itr;
8682  if (!string_to_type_converter((*itr).first,(*itr).second,t2)) return false; ++itr;
8683  return ca(itr,token_list.end());
8684  }
8685 
8686  template <typename InputIterator, typename T1>
8687  inline bool parse(const InputIterator begin, const InputIterator end,
8688  const std::string& delimiters,
8689  T1& t1,
8691  {
8692  typedef typename details::is_valid_iterator<InputIterator>::type itr_type;
8693  typedef std::pair<InputIterator,InputIterator> iterator_type;
8694  typedef typename std::deque<iterator_type>::iterator iterator_type_ptr;
8695  std::deque<iterator_type> token_list;
8696  if (1 == delimiters.size())
8698  begin,end,
8699  std::back_inserter(token_list),
8701  else
8703  begin,end,
8704  std::back_inserter(token_list),
8706  if (token_list.size() < 2) return false;
8707  iterator_type_ptr itr = token_list.begin();
8708  if (!string_to_type_converter((*itr).first,(*itr).second,t1)) return false; ++itr;
8709  return ca(itr,token_list.end());
8710  }
8711 
8712  template <typename InputIterator,
8713  typename T,
8714  typename Allocator,
8715  template <typename,typename> class Sequence>
8716  inline std::size_t parse_n(const InputIterator begin,
8717  const InputIterator end,
8718  const std::string& delimiters,
8719  const std::size_t& n,
8720  Sequence<T,Allocator>& sequence,
8722  {
8723  typedef typename details::is_valid_iterator<InputIterator>::type itr_type;
8724  const std::size_t original_size = sequence.size();
8725  if (1 == delimiters.size())
8727  begin,end,
8728  n,
8729  range_to_type_back_inserter(sequence),
8730  split_option);
8731  else
8733  begin,end,
8734  n,
8735  range_to_type_back_inserter(sequence),
8736  split_option);
8737  return sequence.size() - original_size;
8738  }
8739 
8740  template <typename InputIterator,
8741  typename T,
8742  typename Comparator,
8743  typename Allocator>
8744  inline std::size_t parse_n(const InputIterator begin,
8745  const InputIterator end,
8746  const std::string& delimiters,
8747  const std::size_t& n,
8748  std::set<T,Comparator,Allocator>& set,
8750  {
8751  typedef typename details::is_valid_iterator<InputIterator>::type itr_type;
8752  const std::size_t original_size = set.size();
8753  if (1 == delimiters.size())
8755  begin,end,
8756  n,
8758  split_option);
8759  else
8761  begin,end,
8762  n,
8764  split_option);
8765  return set.size() - original_size;
8766  }
8767 
8768  template <typename InputIterator,
8769  typename T,
8770  typename Comparator,
8771  typename Allocator>
8772  inline std::size_t parse_n(const InputIterator begin,
8773  const InputIterator end,
8774  const std::string& delimiters,
8775  const std::size_t& n,
8776  std::multiset<T,Comparator,Allocator>& multiset,
8778  {
8779  typedef typename details::is_valid_iterator<InputIterator>::type itr_type;
8780  const std::size_t original_size = multiset.size();
8781  if (1 == delimiters.size())
8783  begin,end,
8784  n,
8785  range_to_type_inserter(multiset),
8786  split_option);
8787  else
8789  begin,end,
8790  n,
8791  range_to_type_inserter(multiset),
8792  split_option);
8793  return multiset.size() - original_size;
8794  }
8795 
8796  template <typename InputIterator,
8797  typename T,
8798  typename Container>
8799  inline std::size_t parse_n(const InputIterator begin,
8800  const InputIterator end,
8801  const std::string& delimiters,
8802  const std::size_t& n,
8803  std::queue<T,Container>& queue,
8805  {
8806  typedef typename details::is_valid_iterator<InputIterator>::type itr_type;
8807  const std::size_t original_size = queue.size();
8808  if (1 == delimiters.size())
8810  begin,end,
8811  n,
8813  split_option);
8814  else
8816  begin,end,
8817  n,
8819  split_option);
8820  return queue.size() - original_size;
8821  }
8822 
8823  template <typename InputIterator,
8824  typename T,
8825  typename Container>
8826  inline std::size_t parse_n(const InputIterator begin,
8827  const InputIterator end,
8828  const std::string& delimiters,
8829  const std::size_t& n,
8830  std::stack<T,Container>& stack,
8832  {
8833  typedef typename details::is_valid_iterator<InputIterator>::type itr_type;
8834  const std::size_t original_size = stack.size();
8835  if (1 == delimiters.size())
8837  begin,end,
8838  n,
8840  split_option);
8841  else
8843  begin,end,
8844  n,
8846  split_option);
8847  return stack.size() - original_size;
8848  }
8849 
8850  template <typename InputIterator,
8851  typename T,
8852  typename Container,
8853  typename Comparator>
8854  inline std::size_t parse_n(const InputIterator begin,
8855  const InputIterator end,
8856  const std::string& delimiters,
8857  const std::size_t& n,
8858  std::priority_queue<T,Container,Comparator>& priority_queue,
8860  {
8861  typedef typename details::is_valid_iterator<InputIterator>::type itr_type;
8862  const std::size_t original_size = priority_queue.size();
8863  if (1 == delimiters.size())
8865  begin,end,
8866  n,
8867  range_to_type_push_inserter(priority_queue),
8868  split_option);
8869  else
8871  begin,end,
8872  n,
8873  range_to_type_push_inserter(priority_queue),
8874  split_option);
8875  return priority_queue.size() - original_size;
8876  }
8877 
8878  template <typename InputIterator, typename T>
8879  inline std::size_t parse_n(const InputIterator begin,
8880  const InputIterator end,
8881  const std::string& delimiters,
8882  const std::size_t& n,
8883  T* out,
8885  {
8886  typedef typename details::is_valid_iterator<InputIterator>::type itr_type;
8887  std::size_t insert_count = 0;
8888  if (1 == delimiters.size())
8890  begin,end,
8891  n,
8892  range_to_ptr_type(out,insert_count),
8893  split_option);
8894  else
8896  begin,end,
8897  n,
8898  range_to_ptr_type(out,insert_count),
8899  split_option);
8900  return insert_count;
8901  }
8902 
8903  template <typename InputIterator,
8904  typename T,
8905  typename Allocator,
8906  template <typename,typename> class Sequence>
8907  inline std::size_t parse_n(const std::pair<InputIterator,InputIterator>& range,
8908  const std::string& delimiters,
8909  const std::size_t& n,
8910  Sequence<T,Allocator>& sequence,
8912  {
8913  return parse(range.first,range.second,delimiters,n,sequence,split_option);
8914  }
8915 
8916  template <typename InputIterator,
8917  typename T,
8918  typename Comparator,
8919  typename Allocator>
8920  inline std::size_t parse_n(const std::pair<InputIterator,InputIterator>& range,
8921  const std::string& delimiters,
8922  const std::size_t& n,
8923  std::set<T,Comparator,Allocator>& set,
8925  {
8926  return parse(range.first,range.second,delimiters,n,set,split_option);
8927  }
8928 
8929  template <typename InputIterator,
8930  typename T,
8931  typename Comparator,
8932  typename Allocator>
8933  inline std::size_t parse_n(const std::pair<InputIterator,InputIterator>& range,
8934  const std::string& delimiters,
8935  const std::size_t& n,
8936  std::multiset<T,Comparator,Allocator>& multiset,
8938  {
8939  return parse(range.first,range.second,delimiters,n,multiset,split_option);
8940  }
8941 
8942  template <typename InputIterator,
8943  typename T,
8944  typename Container>
8945  inline std::size_t parse_n(const std::pair<InputIterator,InputIterator>& range,
8946  const std::string& delimiters,
8947  const std::size_t& n,
8948  std::queue<T,Container>& queue,
8950  {
8951  return parse(range.first,range.second,delimiters,n,queue,split_option);
8952  }
8953 
8954  template <typename InputIterator,
8955  typename T,
8956  typename Container>
8957  inline std::size_t parse_n(const std::pair<InputIterator,InputIterator>& range,
8958  const std::string& delimiters,
8959  const std::size_t& n,
8960  std::stack<T,Container>& stack,
8962  {
8963  return parse(range.first,range.second,delimiters,n,stack,split_option);
8964  }
8965 
8966  template <typename InputIterator,
8967  typename T,
8968  typename Container,
8969  typename Comparator>
8970  inline std::size_t parse_n(const std::pair<InputIterator,InputIterator>& range,
8971  const std::string& delimiters,
8972  const std::size_t& n,
8973  std::priority_queue<T,Container,Comparator>& priority_queue,
8975  {
8976  return parse(range.first,range.second,delimiters,n,priority_queue,split_option);
8977  }
8978 
8979  template <typename T1, typename T2, typename T3, typename T4,
8980  typename T5, typename T6, typename T7, typename T8,
8981  typename T9, typename T10, typename T11, typename T12>
8982  inline bool parse(const std::string& data,
8983  const std::string& delimiters,
8984  T1& t1, T2& t2, T3& t3, T4& t4,
8985  T5& t5, T6& t6, T7& t7, T8& t8,
8986  T9& t9, T10& t10, T11& t11, T12& t12)
8987  {
8988  return parse(data.data(),
8989  data.data() + data.size(),
8990  delimiters,
8991  t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,
8993  }
8994 
8995  template <typename T1, typename T2, typename T3, typename T4,
8996  typename T5, typename T6, typename T7, typename T8,
8997  typename T9, typename T10, typename T11>
8998  inline bool parse(const std::string& data,
8999  const std::string& delimiters,
9000  T1& t1, T2& t2, T3& t3, T4& t4,
9001  T5& t5, T6& t6, T7& t7, T8& t8,
9002  T9& t9, T10& t10, T11& t11)
9003  {
9004  return parse(data.data(),
9005  data.data() + data.size(),
9006  delimiters,
9007  t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,
9009  }
9010 
9011  template <typename T1, typename T2, typename T3, typename T4,
9012  typename T5, typename T6, typename T7, typename T8,
9013  typename T9, typename T10>
9014  inline bool parse(const std::string& data,
9015  const std::string& delimiters,
9016  T1& t1, T2& t2, T3& t3, T4& t4,
9017  T5& t5, T6& t6, T7& t7, T8& t8,
9018  T9& t9, T10& t10)
9019  {
9020  return parse(data.data(),
9021  data.data() + data.size(),
9022  delimiters,
9023  t1,t2,t3,t4,t5,t6,t7,t8,t9,
9025  }
9026 
9027  template <typename T1, typename T2, typename T3, typename T4,
9028  typename T5, typename T6, typename T7, typename T8,
9029  typename T9>
9030  inline bool parse(const std::string& data,
9031  const std::string& delimiters,
9032  T1& t1, T2& t2, T3& t3, T4& t4,
9033  T5& t5, T6& t6, T7& t7, T8& t8,
9034  T9& t9)
9035  {
9036  return parse(data.data(),
9037  data.data() + data.size(),
9038  delimiters,
9039  t1,t2,t3,t4,t5,t6,t7,t8,
9041  }
9042 
9043  template <typename T1, typename T2, typename T3, typename T4,
9044  typename T5, typename T6, typename T7, typename T8>
9045  inline bool parse(const std::string& data,
9046  const std::string& delimiters,
9047  T1& t1, T2& t2, T3& t3, T4& t4,
9048  T5& t5, T6& t6, T7& t7, T8& t8)
9049  {
9050  return parse(data.data(),
9051  data.data() + data.size(),
9052  delimiters,
9053  t1,t2,t3,t4,t5,t6,t7,
9055  }
9056 
9057  template <typename T1, typename T2, typename T3, typename T4,
9058  typename T5, typename T6, typename T7>
9059  inline bool parse(const std::string& data,
9060  const std::string& delimiters,
9061  T1& t1, T2& t2, T3& t3, T4& t4,
9062  T5& t5, T6& t6, T7& t7)
9063  {
9064  return parse(data.data(),
9065  data.data() + data.size(),
9066  delimiters,
9067  t1,t2,t3,t4,t5,t6,
9069  }
9070 
9071  template <typename T1, typename T2, typename T3, typename T4,
9072  typename T5, typename T6>
9073  inline bool parse(const std::string& data,
9074  const std::string& delimiters,
9075  T1& t1, T2& t2, T3& t3, T4& t4,
9076  T5& t5, T6& t6)
9077  {
9078  return parse(data.data(),
9079  data.data() + data.size(),
9080  delimiters,
9081  t1,t2,t3,t4,t5,
9083  }
9084 
9085  template <typename T1, typename T2, typename T3, typename T4,
9086  typename T5>
9087  inline bool parse(const std::string& data,
9088  const std::string& delimiters,
9089  T1& t1, T2& t2, T3& t3, T4& t4,
9090  T5& t5)
9091  {
9092  return parse(data.data(),
9093  data.data() + data.size(),
9094  delimiters,
9095  t1,t2,t3,t4,
9097  }
9098 
9099  template <typename T1, typename T2, typename T3, typename T4>
9100  inline bool parse(const std::string& data,
9101  const std::string& delimiters,
9102  T1& t1, T2& t2, T3& t3, T4& t4)
9103  {
9104  return parse(data.data(),
9105  data.data() + data.size(),
9106  delimiters,
9107  t1,t2,t3,
9109  }
9110 
9111  template <typename T1, typename T2, typename T3>
9112  inline bool parse(const std::string& data,
9113  const std::string& delimiters,
9114  T1& t1, T2& t2, T3& t3)
9115  {
9116  return parse(data.data(),
9117  data.data() + data.size(),
9118  delimiters,
9119  t1,t2,
9121  }
9122 
9123  template <typename T1, typename T2>
9124  inline bool parse(const std::string& data,
9125  const std::string& delimiters,
9126  T1& t1, T2& t2)
9127  {
9128  return parse(data.data(),
9129  data.data() + data.size(),
9130  delimiters,
9131  t1,
9133  }
9134 
9135  template <typename T>
9136  inline bool parse(const std::string& data,
9137  const std::string& delimiters,
9138  T& t)
9139  {
9140  return parse(data.data(),
9141  data.data() + data.size(),
9142  delimiters,
9144  }
9145 
9146  template <typename T,
9147  typename Allocator,
9148  template <typename,typename> class Sequence>
9149  inline std::size_t parse(const std::string& data,
9150  const std::string& delimiters,
9151  Sequence<T,Allocator>& sequence,
9153  {
9154  return parse(data.data(),
9155  data.data() + data.size(),
9156  delimiters,
9157  sequence,
9158  split_option);
9159  }
9160 
9161  template <typename T,
9162  typename Comparator,
9163  typename Allocator>
9164  inline std::size_t parse(const std::string& data,
9165  const std::string& delimiters,
9166  std::set<T,Comparator,Allocator>& set,
9168  {
9169  return parse(data.data(),
9170  data.data() + data.size(),
9171  delimiters,
9172  set,
9173  split_option);
9174  }
9175 
9176  template <typename T,
9177  typename Comparator,
9178  typename Allocator>
9179  inline std::size_t parse(const std::string& data,
9180  const std::string& delimiters,
9181  std::multiset<T,Comparator,Allocator>& multiset,
9183  {
9184  return parse(data.data(),
9185  data.data() + data.size(),
9186  delimiters,
9187  multiset,
9188  split_option);
9189  }
9190 
9191  template <typename T,
9192  typename Container>
9193  inline std::size_t parse(const std::string& data,
9194  const std::string& delimiters,
9195  std::queue<T,Container>& queue,
9197  {
9198  return parse(data.data(),
9199  data.data() + data.size(),
9200  delimiters,
9201  queue,
9202  split_option);
9203  }
9204 
9205  template <typename T,
9206  typename Container>
9207  inline std::size_t parse(const std::string& data,
9208  const std::string& delimiters,
9209  std::stack<T,Container>& stack,
9211  {
9212  return parse(data.data(),
9213  data.data() + data.size(),
9214  delimiters,
9215  stack,
9216  split_option);
9217  }
9218 
9219  template <typename T,
9220  typename Container,
9221  typename Comparator>
9222  inline std::size_t parse(const std::string& data,
9223  const std::string& delimiters,
9224  std::priority_queue<T,Container,Comparator>& priority_queue,
9226  {
9227  return parse(data.data(),
9228  data.data() + data.size(),
9229  delimiters,
9230  priority_queue,
9231  split_option);
9232  }
9233 
9234  template <typename T,
9235  typename Allocator,
9236  template <typename,typename> class Sequence>
9237  inline std::size_t parse(const int& argc, char* argv[],
9238  Sequence<T,Allocator>& sequence,
9239  const bool break_on_fail = true)
9240  {
9241  T tmp;
9242  for (int i = 0; i < argc; ++i)
9243  {
9244  if (!string_to_type_converter(std::string(argv[i]),tmp))
9245  {
9246  if (break_on_fail)
9247  return i;
9248  else
9249  continue;
9250  }
9251  sequence.push_back(tmp);
9252  }
9253  return argc;
9254  }
9255 
9256  template <typename T1, typename T2, typename T3, typename T4,
9257  typename T5, typename T6, typename T7, typename T8,
9258  typename T9>
9259  inline std::size_t parse(const int& argc, char* argv[],
9260  T1& t1, T2& t2, T3& t3, T4& t4,
9261  T5& t5, T6& t6, T7& t7, T8& t8,
9262  T9& t9)
9263 
9264  {
9265  if (9 != argc) return 0;
9266  std::size_t result = 0;
9267  if (!string_to_type_converter(std::string(argv[0]),t1)) return result; ++result;
9268  if (!string_to_type_converter(std::string(argv[1]),t2)) return result; ++result;
9269  if (!string_to_type_converter(std::string(argv[2]),t3)) return result; ++result;
9270  if (!string_to_type_converter(std::string(argv[3]),t4)) return result; ++result;
9271  if (!string_to_type_converter(std::string(argv[4]),t5)) return result; ++result;
9272  if (!string_to_type_converter(std::string(argv[5]),t6)) return result; ++result;
9273  if (!string_to_type_converter(std::string(argv[6]),t7)) return result; ++result;
9274  if (!string_to_type_converter(std::string(argv[7]),t8)) return result; ++result;
9275  if (!string_to_type_converter(std::string(argv[8]),t9)) return result; ++result;
9276  return result;
9277  }
9278 
9279  template <typename T1, typename T2, typename T3, typename T4,
9280  typename T5, typename T6, typename T7, typename T8>
9281  inline std::size_t parse(const int& argc, char* argv[],
9282  T1& t1, T2& t2, T3& t3, T4& t4,
9283  T5& t5, T6& t6, T7& t7, T8& t8)
9284 
9285  {
9286  if (8 != argc) return 0;
9287  std::size_t result = 0;
9288  if (!string_to_type_converter(std::string(argv[0]),t1)) return result; ++result;
9289  if (!string_to_type_converter(std::string(argv[1]),t2)) return result; ++result;
9290  if (!string_to_type_converter(std::string(argv[2]),t3)) return result; ++result;
9291  if (!string_to_type_converter(std::string(argv[3]),t4)) return result; ++result;
9292  if (!string_to_type_converter(std::string(argv[4]),t5)) return result; ++result;
9293  if (!string_to_type_converter(std::string(argv[5]),t6)) return result; ++result;
9294  if (!string_to_type_converter(std::string(argv[6]),t7)) return result; ++result;
9295  if (!string_to_type_converter(std::string(argv[7]),t8)) return result; ++result;
9296  return result;
9297  }
9298 
9299  template <typename T1, typename T2, typename T3, typename T4,
9300  typename T5, typename T6, typename T7>
9301  inline std::size_t parse(const int& argc, char* argv[],
9302  T1& t1, T2& t2, T3& t3, T4& t4,
9303  T5& t5, T6& t6, T7& t7)
9304 
9305  {
9306  if (7 != argc) return 0;
9307  std::size_t result = 0;
9308  if (!string_to_type_converter(std::string(argv[0]),t1)) return result; ++result;
9309  if (!string_to_type_converter(std::string(argv[1]),t2)) return result; ++result;
9310  if (!string_to_type_converter(std::string(argv[2]),t3)) return result; ++result;
9311  if (!string_to_type_converter(std::string(argv[3]),t4)) return result; ++result;
9312  if (!string_to_type_converter(std::string(argv[4]),t5)) return result; ++result;
9313  if (!string_to_type_converter(std::string(argv[5]),t6)) return result; ++result;
9314  if (!string_to_type_converter(std::string(argv[6]),t7)) return result; ++result;
9315  return result;
9316  }
9317 
9318  template <typename T1, typename T2, typename T3, typename T4,
9319  typename T5, typename T6>
9320  inline std::size_t parse(const int& argc, char* argv[],
9321  T1& t1, T2& t2, T3& t3, T4& t4,
9322  T5& t5, T6& t6)
9323 
9324  {
9325  if (6 != argc) return 0;
9326  std::size_t result = 0;
9327  if (!string_to_type_converter(std::string(argv[0]),t1)) return result; ++result;
9328  if (!string_to_type_converter(std::string(argv[1]),t2)) return result; ++result;
9329  if (!string_to_type_converter(std::string(argv[2]),t3)) return result; ++result;
9330  if (!string_to_type_converter(std::string(argv[3]),t4)) return result; ++result;
9331  if (!string_to_type_converter(std::string(argv[4]),t5)) return result; ++result;
9332  if (!string_to_type_converter(std::string(argv[5]),t6)) return result; ++result;
9333  return result;
9334  }
9335 
9336  template <typename T1, typename T2, typename T3, typename T4, typename T5>
9337  inline std::size_t parse(const int& argc, char* argv[],
9338  T1& t1, T2& t2, T3& t3, T4& t4, T5& t5)
9339  {
9340  if (5 != argc) return 0;
9341  std::size_t result = 0;
9342  if (!string_to_type_converter(std::string(argv[0]),t1)) return result; ++result;
9343  if (!string_to_type_converter(std::string(argv[1]),t2)) return result; ++result;
9344  if (!string_to_type_converter(std::string(argv[2]),t3)) return result; ++result;
9345  if (!string_to_type_converter(std::string(argv[3]),t4)) return result; ++result;
9346  if (!string_to_type_converter(std::string(argv[4]),t5)) return result; ++result;
9347  return result;
9348  }
9349 
9350  template <typename T1, typename T2, typename T3, typename T4>
9351  inline std::size_t parse(const int& argc, char* argv[],
9352  T1& t1, T2& t2, T3& t3, T4& t4)
9353  {
9354  if (4 != argc) return 0;
9355  std::size_t result = 0;
9356  if (!string_to_type_converter(std::string(argv[0]),t1)) return result; ++result;
9357  if (!string_to_type_converter(std::string(argv[1]),t2)) return result; ++result;
9358  if (!string_to_type_converter(std::string(argv[2]),t3)) return result; ++result;
9359  if (!string_to_type_converter(std::string(argv[3]),t4)) return result; ++result;
9360  return result;
9361  }
9362 
9363  template <typename T1, typename T2, typename T3>
9364  inline std::size_t parse(const int& argc, char* argv[],
9365  T1& t1, T2& t2, T3& t3)
9366  {
9367  if (3 != argc) return 0;
9368  std::size_t result = 0;
9369  if (!string_to_type_converter(std::string(argv[0]),t1)) return result; ++result;
9370  if (!string_to_type_converter(std::string(argv[1]),t2)) return result; ++result;
9371  if (!string_to_type_converter(std::string(argv[2]),t3)) return result; ++result;
9372  return result;
9373  }
9374 
9375  template <typename T1, typename T2>
9376  inline std::size_t parse(const int& argc, char* argv[],
9377  T1& t1, T2& t2)
9378  {
9379  if (2 != argc) return 0;
9380  std::size_t result = 0;
9381  if (!string_to_type_converter(std::string(argv[0]),t1)) return result; ++result;
9382  if (!string_to_type_converter(std::string(argv[1]),t2)) return result; ++result;
9383  return result;
9384  }
9385 
9386  template <typename T1>
9387  inline std::size_t parse(const int& argc, char* argv[],
9388  T1& t1)
9389  {
9390  if (1 != argc) return 0;
9391  std::size_t result = 0;
9392  if (!string_to_type_converter(std::string(argv[0]),t1)) return result; ++result;
9393  return result;
9394  }
9395 
9396  #define strtk_parse_begin(Type)\
9397  namespace strtk {\
9398  bool parse(const std::string& data, const std::string& delimiters, Type& t)\
9399  { return parse(data,delimiters
9400 
9401  #define strtk_parse_type(T)\
9402  ,t.T
9403 
9404  #define strtk_parse_hex_type(T)\
9405  ,t.T
9406 
9407  #define strtk_parse_ignore_token()\
9408  ,ignore_token()
9409 
9410  #define strtk_parse_end()\
9411  );}}
9412 
9413  template <typename T,
9414  typename Allocator,
9415  template <typename,typename> class Sequence>
9416  inline std::size_t parse_n(const std::string& data,
9417  const std::string& delimiters,
9418  const std::size_t& n,
9419  Sequence<T,Allocator>& sequence,
9421  {
9422  return parse_n(data.data(),
9423  data.data() + data.size(),
9424  delimiters,
9425  n,
9426  sequence,
9427  split_option);
9428  }
9429 
9430  template <typename T,
9431  typename Comparator,
9432  typename Allocator>
9433  inline std::size_t parse_n(const std::string& data,
9434  const std::string& delimiters,
9435  const std::size_t& n,
9436  std::set<T,Comparator,Allocator>& set,
9438  {
9439  return parse_n(data.data(),
9440  data.data() + data.size(),
9441  delimiters,
9442  n,
9443  set,
9444  split_option);
9445  }
9446 
9447  template <typename T,
9448  typename Comparator,
9449  typename Allocator>
9450  inline std::size_t parse_n(const std::string& data,
9451  const std::string& delimiters,
9452  const std::size_t& n,
9453  std::multiset<T,Comparator,Allocator>& multiset,
9455  {
9456  return parse_n(data.data(),
9457  data.data() + data.size(),
9458  delimiters,
9459  n,
9460  multiset,
9461  split_option);
9462  }
9463 
9464  template <typename T,
9465  typename Container>
9466  inline std::size_t parse_n(const std::string& data,
9467  const std::string& delimiters,
9468  const std::size_t& n,
9469  std::queue<T,Container>& queue,
9471  {
9472  return parse_n(data.data(),
9473  data.data() + data.size(),
9474  delimiters,
9475  n,
9476  queue,
9477  split_option);
9478  }
9479 
9480  template <typename T,
9481  typename Container>
9482  inline std::size_t parse_n(const std::string& data,
9483  const std::string& delimiters,
9484  const std::size_t& n,
9485  std::stack<T,Container>& stack,
9487  {
9488  return parse_n(data.data(),
9489  data.data() + data.size(),
9490  delimiters,
9491  n,
9492  stack,
9493  split_option);
9494  }
9495 
9496  template <typename T,
9497  typename Container,
9498  typename Comparator>
9499  inline std::size_t parse_n(const std::string& data,
9500  const std::string& delimiters,
9501  const std::size_t& n,
9502  std::priority_queue<T,Container,Comparator>& priority_queue,
9504  {
9505  return parse_n(data.data(),
9506  data.data() + data.size(),
9507  delimiters,
9508  n,
9509  priority_queue,
9510  split_option);
9511  }
9512 
9513  template <typename T>
9514  inline std::size_t parse_n(const std::string& data,
9515  const std::string& delimiters,
9516  const std::size_t& n,
9517  T* out,
9519  {
9520  return parse_n(data.data(),
9521  data.data() + data.size(),
9522  delimiters,
9523  n,
9524  out,
9525  split_option);
9526  }
9527 
9528  template <typename T1, typename T2, typename T3, typename T4,
9529  typename T5, typename T6, typename T7, typename T8,
9530  typename T9, typename T10, typename T11, typename T12>
9531  inline bool parse_line(std::ifstream& stream,
9532  const std::string& delimiters,
9533  T1& t1, T2& t2, T3& t3, T4& t4, T5& t5, T6& t6,
9534  T7& t7, T8& t8, T9& t9, T10& t10, T11& t11, T12& t12)
9535  {
9536  if (!stream)
9537  return false;
9538  std::string data;
9539  data.reserve(strtk::one_kilobyte);
9540  if (!std::getline(stream,data))
9541  return false;
9542  if (data.empty() || delimiters.empty())
9543  return false;
9544  return strtk::parse(data.data(),
9545  data.data() + data.size(),
9546  delimiters,
9547  t1,t2,t3,t4,t5,t6,
9548  t7,t8,t9,t10,t11,t12);
9549  }
9550 
9551  template <typename T1, typename T2, typename T3, typename T4,
9552  typename T5, typename T6, typename T7, typename T8,
9553  typename T9, typename T10, typename T11>
9554  inline bool parse_line(std::ifstream& stream,
9555  const std::string& delimiters,
9556  T1& t1, T2& t2, T3& t3, T4& t4, T5& t5, T6& t6,
9557  T7& t7, T8& t8, T9& t9, T10& t10, T11& t11)
9558  {
9559  if (!stream)
9560  return false;
9561  std::string data;
9562  data.reserve(strtk::one_kilobyte);
9563  if (!std::getline(stream,data))
9564  return false;
9565  if (data.empty() || delimiters.empty())
9566  return false;
9567  return strtk::parse(data.data(),
9568  data.data() + data.size(),
9569  delimiters,
9570  t1,t2,t3,t4,t5,t6,
9571  t7,t8,t9,t10,t11);
9572  }
9573 
9574  template <typename T1, typename T2, typename T3, typename T4,
9575  typename T5, typename T6, typename T7, typename T8,
9576  typename T9, typename T10>
9577  inline bool parse_line(std::ifstream& stream,
9578  const std::string& delimiters,
9579  T1& t1, T2& t2, T3& t3, T4& t4, T5& t5, T6& t6,
9580  T7& t7, T8& t8, T9& t9, T10& t10)
9581  {
9582  if (!stream)
9583  return false;
9584  std::string data;
9585  data.reserve(strtk::one_kilobyte);
9586  if (!std::getline(stream,data))
9587  return false;
9588  if (data.empty() || delimiters.empty())
9589  return false;
9590  return strtk::parse(data.data(),
9591  data.data() + data.size(),
9592  delimiters,
9593  t1,t2,t3,t4,t5,t6,
9594  t7,t8,t9,t10);
9595  }
9596 
9597  template <typename T1, typename T2, typename T3, typename T4,
9598  typename T5, typename T6, typename T7, typename T8,
9599  typename T9>
9600  inline bool parse_line(std::ifstream& stream,
9601  const std::string& delimiters,
9602  T1& t1, T2& t2, T3& t3, T4& t4, T5& t5, T6& t6,
9603  T7& t7, T8& t8, T9& t9)
9604  {
9605  if (!stream)
9606  return false;
9607  std::string data;
9608  data.reserve(strtk::one_kilobyte);
9609  if (!std::getline(stream,data))
9610  return false;
9611  if (data.empty() || delimiters.empty())
9612  return false;
9613  return strtk::parse(data.data(),
9614  data.data() + data.size(),
9615  delimiters,
9616  t1,t2,t3,t4,t5,t6,
9617  t7,t8,t9);
9618  }
9619 
9620  template <typename T1, typename T2, typename T3, typename T4,
9621  typename T5, typename T6, typename T7, typename T8>
9622  inline bool parse_line(std::ifstream& stream,
9623  const std::string& delimiters,
9624  T1& t1, T2& t2, T3& t3, T4& t4, T5& t5, T6& t6,
9625  T7& t7, T8& t8)
9626  {
9627  if (!stream)
9628  return false;
9629  std::string data;
9630  data.reserve(strtk::one_kilobyte);
9631  if (!std::getline(stream,data))
9632  return false;
9633  if (data.empty() || delimiters.empty())
9634  return false;
9635  return strtk::parse(data.data(),
9636  data.data() + data.size(),
9637  delimiters,
9638  t1,t2,t3,t4,t5,t6,
9639  t7,t8);
9640  }
9641 
9642  template <typename T1, typename T2, typename T3, typename T4,
9643  typename T5, typename T6, typename T7>
9644  inline bool parse_line(std::ifstream& stream,
9645  const std::string& delimiters,
9646  T1& t1, T2& t2, T3& t3, T4& t4, T5& t5, T6& t6,
9647  T7& t7)
9648  {
9649  if (!stream)
9650  return false;
9651  std::string data;
9652  data.reserve(strtk::one_kilobyte);
9653  if (!std::getline(stream,data))
9654  return false;
9655  if (data.empty() || delimiters.empty())
9656  return false;
9657  return strtk::parse(data.data(),
9658  data.data() + data.size(),
9659  delimiters,
9660  t1,t2,t3,t4,t5,t6,t7);
9661  }
9662 
9663  template <typename T1, typename T2, typename T3, typename T4,
9664  typename T5, typename T6>
9665  inline bool parse_line(std::ifstream& stream,
9666  const std::string& delimiters,
9667  T1& t1, T2& t2, T3& t3, T4& t4, T5& t5, T6& t6)
9668  {
9669  if (!stream)
9670  return false;
9671  std::string data;
9672  data.reserve(strtk::one_kilobyte);
9673  if (!std::getline(stream,data))
9674  return false;
9675  if (data.empty() || delimiters.empty())
9676  return false;
9677  return strtk::parse(data.data(),
9678  data.data() + data.size(),
9679  delimiters,
9680  t1,t2,t3,t4,t5,t6);
9681  }
9682 
9683  template <typename T1, typename T2, typename T3, typename T4,
9684  typename T5>
9685  inline bool parse_line(std::ifstream& stream,
9686  const std::string& delimiters,
9687  T1& t1, T2& t2, T3& t3, T4& t4, T5& t5)
9688  {
9689  if (!stream)
9690  return false;
9691  std::string data;
9692  data.reserve(strtk::one_kilobyte);
9693  if (!std::getline(stream,data))
9694  return false;
9695  if (data.empty() || delimiters.empty())
9696  return false;
9697  return strtk::parse(data.data(),
9698  data.data() + data.size(),
9699  delimiters,
9700  t1,t2,t3,t4,t5);
9701  }
9702 
9703  template <typename T1, typename T2, typename T3, typename T4>
9704  inline bool parse_line(std::ifstream& stream,
9705  const std::string& delimiters,
9706  T1& t1, T2& t2, T3& t3, T4& t4)
9707  {
9708  if (!stream)
9709  return false;
9710  std::string data;
9711  data.reserve(strtk::one_kilobyte);
9712  if (!std::getline(stream,data))
9713  return false;
9714  if (data.empty() || delimiters.empty())
9715  return false;
9716  return strtk::parse(data.data(),
9717  data.data() + data.size(),
9718  delimiters,
9719  t1,t2,t3,t4);
9720  }
9721 
9722  template <typename T1, typename T2, typename T3>
9723  inline bool parse_line(std::ifstream& stream,
9724  const std::string& delimiters,
9725  T1& t1, T2& t2, T3& t3)
9726  {
9727  if (!stream)
9728  return false;
9729  std::string data;
9730  data.reserve(strtk::one_kilobyte);
9731  if (!std::getline(stream,data))
9732  return false;
9733  if (data.empty() || delimiters.empty())
9734  return false;
9735  return strtk::parse(data.data(),
9736  data.data() + data.size(),
9737  delimiters,
9738  t1,t2,t3);
9739  }
9740 
9741  template <typename T1, typename T2>
9742  inline bool parse_line(std::ifstream& stream,
9743  const std::string& delimiters,
9744  T1& t1, T2& t2)
9745  {
9746  if (!stream)
9747  return false;
9748  std::string data;
9749  data.reserve(strtk::one_kilobyte);
9750  if (!std::getline(stream,data))
9751  return false;
9752  if (data.empty() || delimiters.empty())
9753  return false;
9754  return strtk::parse(data.data(),
9755  data.data() + data.size(),
9756  delimiters,
9757  t1,t2);
9758  }
9759 
9760  template <typename T1>
9761  inline bool parse_line(std::ifstream& stream,
9762  const std::string& delimiters,
9763  T1& t1)
9764  {
9765  if (!stream)
9766  return false;
9767  std::string data;
9768  data.reserve(strtk::one_kilobyte);
9769  if (!std::getline(stream,data))
9770  return false;
9771  if (data.empty() || delimiters.empty())
9772  return false;
9773  return strtk::parse(data.data(),
9774  data.data() + data.size(),
9775  delimiters,
9776  t1);
9777  }
9778 
9779  template <typename T,
9780  typename Allocator,
9781  template <typename,typename> class Sequence>
9782  inline std::size_t parse_line(std::ifstream& stream,
9783  const std::string& delimiters,
9784  Sequence<T,Allocator>& sequence,
9786  {
9787  if (!stream)
9788  return 0;
9789  std::string data;
9790  data.reserve(strtk::one_kilobyte);
9791  if (!std::getline(stream,data))
9792  return 0;
9793  if (data.empty() || delimiters.empty())
9794  return false;
9795  return strtk::parse(data.data(),
9796  data.data() + data.size(),
9797  delimiters,
9798  sequence,
9799  split_option);
9800  }
9801 
9802  template <typename T,
9803  typename Comparator,
9804  typename Allocator>
9805  inline std::size_t parse_line(std::ifstream& stream,
9806  const std::string& delimiters,
9807  std::set<T,Comparator,Allocator>& set,
9809  {
9810  if (!stream)
9811  return 0;
9812  std::string data;
9813  data.reserve(strtk::one_kilobyte);
9814  if (!std::getline(stream,data))
9815  return 0;
9816  if (data.empty() || delimiters.empty())
9817  return false;
9818  return strtk::parse(data.data(),
9819  data.data() + data.size(),
9820  delimiters,
9821  set,
9822  split_option);
9823  }
9824 
9825  template <typename T,
9826  typename Comparator,
9827  typename Allocator>
9828  inline std::size_t parse_line(std::ifstream& stream,
9829  const std::string& delimiters,
9830  std::multiset<T,Comparator,Allocator>& multiset,
9832  {
9833  if (!stream)
9834  return 0;
9835  std::string data;
9836  data.reserve(strtk::one_kilobyte);
9837  if (!std::getline(stream,data))
9838  return 0;
9839  if (data.empty() || delimiters.empty())
9840  return false;
9841  return strtk::parse(data.data(),
9842  data.data() + data.size(),
9843  delimiters,
9844  multiset,
9845  split_option);
9846  }
9847 
9848  template <typename T,
9849  typename Container>
9850  inline std::size_t parse_line(std::ifstream& stream,
9851  const std::string& delimiters,
9852  std::queue<T,Container>& queue,
9854  {
9855  if (!stream)
9856  return 0;
9857  std::string data;
9858  data.reserve(strtk::one_kilobyte);
9859  if (!std::getline(stream,data))
9860  return 0;
9861  if (data.empty() || delimiters.empty())
9862  return false;
9863  return strtk::parse(data.data(),
9864  data.data() + data.size(),
9865  delimiters,
9866  queue,
9867  split_option);
9868  }
9869 
9870  template <typename T,
9871  typename Container>
9872  inline std::size_t parse_line(std::ifstream& stream,
9873  const std::string& delimiters,
9874  std::stack<T,Container>& stack,
9876  {
9877  if (!stream)
9878  return 0;
9879  std::string data;
9880  data.reserve(strtk::one_kilobyte);
9881  if (!std::getline(stream,data))
9882  return 0;
9883  if (data.empty() || delimiters.empty())
9884  return false;
9885  return strtk::parse(data.data(),
9886  data.data() + data.size(),
9887  delimiters,
9888  stack,
9889  split_option);
9890  }
9891 
9892  template <typename T,
9893  typename Container,
9894  typename Comparator>
9895  inline std::size_t parse_line(std::ifstream& stream,
9896  const std::string& delimiters,
9897  std::priority_queue<T,Container,Comparator>& priority_queue,
9899 
9900  {
9901  if (!stream)
9902  return 0;
9903  std::string data;
9904  data.reserve(strtk::one_kilobyte);
9905  if (!std::getline(stream,data))
9906  return 0;
9907  if (data.empty() || delimiters.empty())
9908  return false;
9909  return strtk::parse(data.data(),
9910  data.data() + data.size(),
9911  delimiters,
9912  priority_queue,
9913  split_option);
9914  }
9915 
9916  template <typename T,
9917  typename Allocator,
9918  template <typename,typename> class Sequence>
9919  inline std::size_t parse_line_n(std::ifstream& stream,
9920  const std::string& delimiters,
9921  const std::size_t& n,
9922  Sequence<T,Allocator>& sequence,
9924  {
9925  if (!stream)
9926  return 0;
9927  std::string data;
9928  data.reserve(strtk::one_kilobyte);
9929  if (!std::getline(stream,data))
9930  return 0;
9931  if (data.empty() || delimiters.empty())
9932  return 0;
9933  return strtk::parse_n(data.data(),
9934  data.data() + data.size(),
9935  delimiters,
9936  n,
9937  sequence,
9938  split_option);
9939  }
9940 
9941  template <typename T,
9942  typename Comparator,
9943  typename Allocator>
9944  inline std::size_t parse_line_n(std::ifstream& stream,
9945  const std::string& delimiters,
9946  const std::size_t& n,
9947  std::set<T,Comparator,Allocator>& set,
9949  {
9950  if (!stream)
9951  return 0;
9952  std::string data;
9953  data.reserve(strtk::one_kilobyte);
9954  if (!std::getline(stream,data))
9955  return 0;
9956  if (data.empty() || delimiters.empty())
9957  return 0;
9958  return strtk::parse_n(data.data(),
9959  data.data() + data.size(),
9960  delimiters,
9961  n,
9962  set,
9963  split_option);
9964  }
9965 
9966  template <typename T,
9967  typename Comparator,
9968  typename Allocator>
9969  inline std::size_t parse_line_n(std::ifstream& stream,
9970  const std::string& delimiters,
9971  const std::size_t& n,
9972  std::multiset<T,Comparator,Allocator>& multiset,
9974  {
9975  if (!stream)
9976  return 0;
9977  std::string data;
9978  data.reserve(strtk::one_kilobyte);
9979  if (!std::getline(stream,data))
9980  return 0;
9981  if (data.empty() || delimiters.empty())
9982  return 0;
9983  return strtk::parse_n(data.data(),
9984  data.data() + data.size(),
9985  delimiters,
9986  n,
9987  multiset,
9988  split_option);
9989  }
9990 
9991  template <typename T,
9992  typename Container>
9993  inline std::size_t parse_line_n(std::ifstream& stream,
9994  const std::string& delimiters,
9995  const std::size_t& n,
9996  std::queue<T,Container>& queue,
9998  {
9999  if (!stream)
10000  return 0;
10001  std::string data;
10002  data.reserve(strtk::one_kilobyte);
10003  if (!std::getline(stream,data))
10004  return 0;
10005  if (data.empty() || delimiters.empty())
10006  return 0;
10007  return strtk::parse_n(data.data(),
10008  data.data() + data.size(),
10009  delimiters,
10010  n,
10011  queue,
10012  split_option);
10013  }
10014 
10015  template <typename T,
10016  typename Container>
10017  inline std::size_t parse_line_n(std::ifstream& stream,
10018  const std::string& delimiters,
10019  const std::size_t& n,
10020  std::stack<T,Container>& stack,
10022  {
10023  if (!stream)
10024  return 0;
10025  std::string data;
10026  data.reserve(strtk::one_kilobyte);
10027  if (!std::getline(stream,data))
10028  return 0;
10029  if (data.empty() || delimiters.empty())
10030  return 0;
10031  return strtk::parse_n(data.data(),
10032  data.data() + data.size(),
10033  delimiters,
10034  n,
10035  stack,
10036  split_option);
10037  }
10038 
10039  template <typename T,
10040  typename Container,
10041  typename Comparator>
10042  inline std::size_t parse_line_n(std::ifstream& stream,
10043  const std::string& delimiters,
10044  const std::size_t& n,
10045  std::priority_queue<T,Container,Comparator>& priority_queue,
10047 
10048  {
10049  if (!stream)
10050  return 0;
10051  std::string data;
10052  data.reserve(strtk::one_kilobyte);
10053  if (!std::getline(stream,data))
10054  return 0;
10055  if (data.empty() || delimiters.empty())
10056  return 0;
10057  return strtk::parse_n(data.data(),
10058  data.data() + data.size(),
10059  delimiters,
10060  n,
10061  priority_queue,
10062  split_option);
10063  }
10064 
10065  template <typename T1, typename T2, typename T3, typename T4,
10066  typename T5, typename T6, typename T7, typename T8,
10067  typename T9, typename T10, typename T11, typename T12>
10068  inline void construct(std::string& output,
10069  const std::string& delimiter,
10070  const T1& t1, const T2& t2, const T3& t3, const T4& t4,
10071  const T5& t5, const T6& t6, const T7& t7, const T8& t8,
10072  const T9& t9, const T10& t10, const T11& t11, const T12& t12)
10073  {
10074  output += type_to_string( t1); output += delimiter;
10075  output += type_to_string( t2); output += delimiter;
10076  output += type_to_string( t3); output += delimiter;
10077  output += type_to_string( t4); output += delimiter;
10078  output += type_to_string( t5); output += delimiter;
10079  output += type_to_string( t6); output += delimiter;
10080  output += type_to_string( t7); output += delimiter;
10081  output += type_to_string( t8); output += delimiter;
10082  output += type_to_string( t9); output += delimiter;
10083  output += type_to_string(t10); output += delimiter;
10084  output += type_to_string(t11); output += delimiter;
10085  output += type_to_string(t12);
10086  }
10087 
10088  template <typename T1, typename T2, typename T3, typename T4,
10089  typename T5, typename T6, typename T7, typename T8,
10090  typename T9, typename T10, typename T11>
10091  inline void construct(std::string& output,
10092  const std::string& delimiter,
10093  const T1& t1, const T2& t2, const T3& t3, const T4& t4,
10094  const T5& t5, const T6& t6, const T7& t7, const T8& t8,
10095  const T9& t9, const T10& t10, const T11& t11)
10096  {
10097  output += type_to_string( t1); output += delimiter;
10098  output += type_to_string( t2); output += delimiter;
10099  output += type_to_string( t3); output += delimiter;
10100  output += type_to_string( t4); output += delimiter;
10101  output += type_to_string( t5); output += delimiter;
10102  output += type_to_string( t6); output += delimiter;
10103  output += type_to_string( t7); output += delimiter;
10104  output += type_to_string( t8); output += delimiter;
10105  output += type_to_string( t9); output += delimiter;
10106  output += type_to_string(t10); output += delimiter;
10107  output += type_to_string(t11);
10108  }
10109 
10110  template <typename T1, typename T2, typename T3, typename T4,
10111  typename T5, typename T6, typename T7, typename T8,
10112  typename T9, typename T10>
10113  inline void construct(std::string& output,
10114  const std::string& delimiter,
10115  const T1& t1, const T2& t2, const T3& t3, const T4& t4,
10116  const T5& t5, const T6& t6, const T7& t7, const T8& t8,
10117  const T9& t9, const T10& t10)
10118  {
10119  output += type_to_string(t1); output += delimiter;
10120  output += type_to_string(t2); output += delimiter;
10121  output += type_to_string(t3); output += delimiter;
10122  output += type_to_string(t4); output += delimiter;
10123  output += type_to_string(t5); output += delimiter;
10124  output += type_to_string(t6); output += delimiter;
10125  output += type_to_string(t7); output += delimiter;
10126  output += type_to_string(t8); output += delimiter;
10127  output += type_to_string(t9); output += delimiter;
10128  output += type_to_string(t10);
10129  }
10130 
10131  template <typename T1, typename T2, typename T3, typename T4,
10132  typename T5, typename T6, typename T7, typename T8,
10133  typename T9>
10134  inline void construct(std::string& output,
10135  const std::string& delimiter,
10136  const T1& t1, const T2& t2, const T3& t3, const T4& t4,
10137  const T5& t5, const T6& t6, const T7& t7, const T8& t8,
10138  const T9& t9)
10139  {
10140  output += type_to_string(t1); output += delimiter;
10141  output += type_to_string(t2); output += delimiter;
10142  output += type_to_string(t3); output += delimiter;
10143  output += type_to_string(t4); output += delimiter;
10144  output += type_to_string(t5); output += delimiter;
10145  output += type_to_string(t6); output += delimiter;
10146  output += type_to_string(t7); output += delimiter;
10147  output += type_to_string(t8); output += delimiter;
10148  output += type_to_string(t9);
10149  }
10150 
10151  template <typename T1, typename T2, typename T3, typename T4,
10152  typename T5, typename T6, typename T7, typename T8>
10153  inline void construct(std::string& output,
10154  const std::string& delimiter,
10155  const T1& t1, const T2& t2, const T3& t3, const T4& t4,
10156  const T5& t5, const T6& t6, const T7& t7, const T8& t8)
10157  {
10158  output += type_to_string(t1); output += delimiter;
10159  output += type_to_string(t2); output += delimiter;
10160  output += type_to_string(t3); output += delimiter;
10161  output += type_to_string(t4); output += delimiter;
10162  output += type_to_string(t5); output += delimiter;
10163  output += type_to_string(t6); output += delimiter;
10164  output += type_to_string(t7); output += delimiter;
10165  output += type_to_string(t8);
10166  }
10167 
10168  template <typename T1, typename T2, typename T3, typename T4,
10169  typename T5, typename T6, typename T7>
10170  inline void construct(std::string& output,
10171  const std::string& delimiter,
10172  const T1& t1, const T2& t2, const T3& t3, const T4& t4,
10173  const T5& t5, const T6& t6, const T7& t7)
10174  {
10175  output += type_to_string(t1); output += delimiter;
10176  output += type_to_string(t2); output += delimiter;
10177  output += type_to_string(t3); output += delimiter;
10178  output += type_to_string(t4); output += delimiter;
10179  output += type_to_string(t5); output += delimiter;
10180  output += type_to_string(t6); output += delimiter;
10181  output += type_to_string(t7);
10182  }
10183 
10184  template <typename T1, typename T2, typename T3, typename T4,
10185  typename T5,typename T6>
10186  inline void construct(std::string& output,
10187  const std::string& delimiter,
10188  const T1& t1, const T2& t2, const T3& t3, const T4& t4,
10189  const T5& t5, const T6& t6)
10190  {
10191  output += type_to_string(t1); output += delimiter;
10192  output += type_to_string(t2); output += delimiter;
10193  output += type_to_string(t3); output += delimiter;
10194  output += type_to_string(t4); output += delimiter;
10195  output += type_to_string(t5); output += delimiter;
10196  output += type_to_string(t6);
10197  }
10198 
10199  template <typename T1, typename T2, typename T3, typename T4,
10200  typename T5>
10201  inline void construct(std::string& output,
10202  const std::string& delimiter,
10203  const T1& t1, const T2& t2, const T3& t3, const T4& t4,
10204  const T5& t5)
10205  {
10206  output += type_to_string(t1); output += delimiter;
10207  output += type_to_string(t2); output += delimiter;
10208  output += type_to_string(t3); output += delimiter;
10209  output += type_to_string(t4); output += delimiter;
10210  output += type_to_string(t5);
10211  }
10212 
10213  template <typename T1, typename T2, typename T3, typename T4>
10214  inline void construct(std::string& output,
10215  const std::string& delimiter,
10216  const T1& t1, const T2& t2, const T3& t3, const T4& t4)
10217  {
10218  output += type_to_string(t1); output += delimiter;
10219  output += type_to_string(t2); output += delimiter;
10220  output += type_to_string(t3); output += delimiter;
10221  output += type_to_string(t4);
10222  }
10223 
10224  template <typename T1, typename T2, typename T3>
10225  inline void construct(std::string& output,
10226  const std::string& delimiter,
10227  const T1& t1, const T2& t2, const T3& t3)
10228  {
10229  output += type_to_string(t1); output += delimiter;
10230  output += type_to_string(t2); output += delimiter;
10231  output += type_to_string(t3);
10232  }
10233 
10234  template <typename T1, typename T2>
10235  inline void construct(std::string& output,
10236  const std::string& delimiter,
10237  const T1& t1, const T2& t2)
10238  {
10239  output += type_to_string(t1); output += delimiter;
10240  output += type_to_string(t2);
10241  }
10242 
10243  template <typename InputIterator>
10244  inline void join(std::string& output,
10245  const std::string& delimiter,
10246  const InputIterator begin,
10247  const InputIterator end)
10248  {
10249  InputIterator itr = begin;
10250  while (end != itr)
10251  {
10252  output += type_to_string(*itr);
10253  if (end == (++itr))
10254  break;
10255  else
10256  output += delimiter;
10257  }
10258  }
10259 
10260  template <typename InputIterator>
10261  inline void join(std::string& output,
10262  const std::string& delimiter,
10263  const std::pair<InputIterator,InputIterator>& range)
10264  {
10265  InputIterator itr = range.first;
10266  while (range.second != itr)
10267  {
10268  output += type_to_string(*itr);
10269  if (range.second == (++itr))
10270  break;
10271  else
10272  output += delimiter;
10273  }
10274  }
10275 
10276  template <typename T,
10277  typename Allocator,
10278  template <typename,typename> class Sequence>
10279  inline void join(std::string& output,
10280  const std::string& delimiter,
10281  const Sequence<T,Allocator>& sequence)
10282  {
10283  join(output,delimiter,sequence.begin(),sequence.end());
10284  }
10285 
10286  template <typename T,
10287  typename Comparator,
10288  typename Allocator>
10289  inline void join(std::string& output,
10290  const std::string& delimiter,
10291  const std::set<T,Comparator,Allocator>& set)
10292  {
10293  join(output,delimiter,set.begin(),set.end());
10294  }
10295 
10296  template <typename T,
10297  typename Comparator,
10298  typename Allocator>
10299  inline void join(std::string& output,
10300  const std::string& delimiter,
10301  const std::multiset<T,Comparator,Allocator>& multiset)
10302  {
10303  join(output,delimiter,multiset.begin(),multiset.end());
10304  }
10305 
10306  inline void join(std::string& output,
10307  const std::string& delimiter,
10308  int argc, char* argv[])
10309  {
10310  for (int i = 0; i < argc; ++i)
10311  {
10312  output += argv[i];
10313  if (i < (argc - 1))
10314  output += delimiter;
10315  }
10316  }
10317 
10318  template <typename InputIterator>
10319  inline std::string join(const std::string& delimiter,
10320  const InputIterator begin,
10321  const InputIterator end)
10322  {
10323  std::string output;
10324  output.reserve(one_kilobyte);
10325  join(output,delimiter,begin,end);
10326  return output;
10327  }
10328 
10329  template <typename InputIterator>
10330  inline std::string join(const std::string& delimiter,
10331  const std::pair<InputIterator,InputIterator>& range)
10332  {
10333  std::string output;
10334  output.reserve(one_kilobyte);
10335  join(output,delimiter,range.first,range.second);
10336  return output;
10337  }
10338 
10339  template <typename T,
10340  typename Allocator,
10341  template <typename,typename> class Sequence>
10342  inline std::string join(const std::string& delimiter,
10343  const Sequence<T,Allocator>& sequence)
10344  {
10345  if (sequence.empty())
10346  return "";
10347  else
10348  return join(delimiter,sequence.begin(),sequence.end());
10349  }
10350 
10351  template <typename T,
10352  typename Comparator,
10353  typename Allocator>
10354  inline std::string join(const std::string& delimiter,
10355  const std::set<T,Comparator,Allocator>& set)
10356  {
10357  if (set.empty())
10358  return "";
10359  else
10360  return join(delimiter,set.begin(),set.end());
10361  }
10362 
10363  template <typename T,
10364  typename Comparator,
10365  typename Allocator>
10366  inline std::string join(const std::string& delimiter,
10367  const std::multiset<T,Comparator,Allocator>& multiset)
10368  {
10369  if (multiset.empty())
10370  return "";
10371  else
10372  return join(delimiter,multiset.begin(),multiset.end());
10373  }
10374 
10375  inline std::string join(const std::string& delimiter, int argc, char* argv[])
10376  {
10377  std::string result;
10378  result.reserve(one_kilobyte);
10379  join(result,delimiter,argc,argv);
10380  return result;
10381  }
10382 
10383  template <typename InputIterator, typename Predicate>
10384  inline void join_if(std::string& output,
10385  const std::string& delimiter,
10386  Predicate predicate,
10387  const InputIterator begin,
10388  const InputIterator end)
10389  {
10390  InputIterator itr = begin;
10391  bool first_time = true;
10392  while (end != itr)
10393  {
10394  if (predicate(*itr))
10395  {
10396  if (!first_time)
10397  output += delimiter;
10398  else
10399  first_time = false;
10400  output += type_to_string(*itr);
10401  }
10402  if (end == (++itr))
10403  break;
10404  }
10405  }
10406 
10407  template <typename InputIterator, typename Predicate>
10408  inline void join_if(std::string& output,
10409  const std::string& delimiter,
10410  Predicate predicate,
10411  const std::pair<InputIterator,InputIterator>& range)
10412  {
10413  InputIterator itr = range.first;
10414  bool first_time = true;
10415  while (range.second != itr)
10416  {
10417  if (predicate(*itr))
10418  {
10419  if (!first_time)
10420  output += delimiter;
10421  else
10422  first_time = false;
10423  output += type_to_string(*itr);
10424  }
10425  if (range.second == (++itr))
10426  break;
10427  }
10428  }
10429 
10430  template <typename T,
10431  typename Predicate,
10432  typename Allocator,
10433  template <typename,typename> class Sequence>
10434  inline void join_if(std::string& output,
10435  const std::string& delimiter,
10436  Predicate predicate,
10437  const Sequence<T,Allocator>& sequence)
10438  {
10439  join_if(output,delimiter,predicate,sequence.begin(),sequence.end());
10440  }
10441 
10442  template <typename T,
10443  typename Predicate,
10444  typename Comparator,
10445  typename Allocator>
10446  inline void join_if(std::string& output,
10447  const std::string& delimiter,
10448  Predicate predicate,
10449  const std::set<T,Comparator,Allocator>& set)
10450  {
10451  join_if(output,delimiter,predicate,set.begin(),set.end());
10452  }
10453 
10454  template <typename T,
10455  typename Predicate,
10456  typename Comparator,
10457  typename Allocator>
10458  inline void join_if(std::string& output,
10459  const std::string& delimiter,
10460  Predicate predicate,
10461  const std::multiset<T,Comparator,Allocator>& multiset)
10462  {
10463  join_if(output,delimiter,predicate,multiset.begin(),multiset.end());
10464  }
10465 
10466  template <typename InputIterator, typename Predicate>
10467  inline std::string join_if(const std::string& delimiter,
10468  Predicate predicate,
10469  const InputIterator begin,
10470  const InputIterator end)
10471  {
10472  std::string output;
10473  output.reserve(one_kilobyte);
10474  join_if(output,delimiter,predicate,begin,end);
10475  return output;
10476  }
10477 
10478  template <typename InputIterator, typename Predicate>
10479  inline std::string join_if(const std::string& delimiter,
10480  Predicate predicate,
10481  const std::pair<InputIterator,InputIterator>& range)
10482  {
10483  std::string output;
10484  output.reserve(one_kilobyte);
10485  join_if(output,delimiter,predicate,range.first,range.second);
10486  return output;
10487  }
10488 
10489  template <typename T,
10490  typename Predicate,
10491  typename Allocator,
10492  template <typename,typename> class Sequence>
10493  inline std::string join_if(const std::string& delimiter,
10494  Predicate predicate,
10495  const Sequence<T,Allocator>& sequence)
10496  {
10497  return join(delimiter,predicate,sequence.begin(),sequence.end());
10498  }
10499 
10500  template <typename T,
10501  typename Predicate,
10502  typename Comparator,
10503  typename Allocator>
10504  inline std::string join_if(const std::string& delimiter,
10505  Predicate predicate,
10506  const std::set<T,Comparator,Allocator>& set)
10507  {
10508  return join_if(delimiter,predicate,set.begin(),set.end());
10509  }
10510 
10511  template <typename T,
10512  typename Predicate,
10513  typename Comparator,
10514  typename Allocator>
10515  inline std::string join_if(const std::string& delimiter,
10516  Predicate predicate,
10517  const std::multiset<T,Comparator,Allocator>& multiset)
10518  {
10519  return join_if(delimiter,predicate,multiset.begin(),multiset.end());
10520  }
10521 
10523  {
10524  public:
10525 
10526  build_string(const std::size_t& initial_size = 64)
10527  {
10528  data_.reserve(initial_size);
10529  }
10530 
10531  template <typename T>
10532  inline build_string& operator << (const T& t)
10533  {
10534  data_ += type_to_string(t);
10535  return (*this);
10536  }
10537 
10538  inline operator std::string () const
10539  {
10540  return data_;
10541  }
10542 
10543  inline std::string as_string() const
10544  {
10545  return data_;
10546  }
10547 
10548  inline operator const char* () const
10549  {
10550  return data_.data();
10551  }
10552 
10553  private:
10554 
10555  std::string data_;
10556  };
10557 
10558  inline void replicate(const std::size_t& n,
10559  const std::string& str,
10560  std::string& output)
10561  {
10562  if (0 == n) return;
10563  output.reserve(output.size() + (str.size() * n));
10564  for (std::size_t i = 0; i < n; ++i)
10565  {
10566  output.append(str);
10567  }
10568  }
10569 
10570  inline std::string replicate(const std::size_t& n,
10571  const std::string& str)
10572  {
10573  std::string output;
10574  replicate(n,str,output);
10575  return output;
10576  }
10577 
10578  inline void replicate_inplace(const std::size_t& n,
10579  std::string& str)
10580  {
10581  std::string temp_str = str;
10582  str.reserve(str.size() + (str.size() * n));
10583 
10584  for (std::size_t i = 0; i < n; ++i)
10585  {
10586  str.append(temp_str);
10587  }
10588  }
10589 
10590  template <typename InputIterator>
10591  inline void bracketize(std::string& output,
10592  const std::string& pre,
10593  const std::string& post,
10594  const InputIterator begin,
10595  const InputIterator end)
10596  {
10597  InputIterator itr = begin;
10598  std::string s;
10599  s.reserve(one_kilobyte);
10600  while (end != itr)
10601  {
10602  s.clear();
10603  s.append(pre);
10604  s.append(type_to_string(*itr));
10605  s.append(post);
10606  output.append(s);
10607  ++itr;
10608  }
10609  }
10610 
10611  template <typename T,
10612  typename Allocator,
10613  template <typename,typename> class Sequence>
10614  inline void bracketize(std::string& output,
10615  const std::string& pre,
10616  const std::string& post,
10617  Sequence<T,Allocator>& sequence)
10618  {
10619  bracketize(output,pre,post,sequence.begin(),sequence.end());
10620  }
10621 
10622  template <typename T,
10623  typename Comparator,
10624  typename Allocator>
10625  inline void bracketize(std::string& output,
10626  const std::string& pre,
10627  const std::string& post,
10628  std::set<T,Comparator,Allocator>& set)
10629  {
10630  bracketize(output,pre,post,set.begin(),set.end());
10631  }
10632 
10633  template <typename T,
10634  typename Comparator,
10635  typename Allocator>
10636  inline void bracketize(std::string& output,
10637  const std::string& pre,
10638  const std::string& post,
10639  std::multiset<T,Comparator,Allocator>& multiset)
10640  {
10641  bracketize(output,pre,post,multiset.begin(),multiset.end());
10642  }
10643 
10644  template <typename InputIterator>
10646  const std::string& post,
10647  const InputIterator begin,
10648  const InputIterator end)
10649  {
10650  std::string output;
10651  output.reserve(one_kilobyte);
10652  bracketize(output,pre,post,begin,end);
10653  return output;
10654  }
10655 
10656  template <typename T,
10657  typename Allocator,
10658  template <typename,typename> class Sequence>
10660  const std::string& post,
10661  Sequence<T,Allocator>& sequence)
10662  {
10663  return bracketize(pre,post,sequence.begin(),sequence.end());
10664  }
10665 
10666  template <typename T,
10667  typename Comparator,
10668  typename Allocator>
10670  const std::string& post,
10671  std::set<T,Comparator,Allocator>& set)
10672  {
10673  return bracketize(pre,post,set.begin(),set.end());
10674  }
10675 
10676  template <typename T,
10677  typename Comparator,
10678  typename Allocator>
10680  const std::string& post,
10681  std::multiset<T,Comparator,Allocator>& multiset)
10682  {
10683  return bracketize(pre,post,multiset.begin(),multiset.end());
10684  }
10685 
10686  template <typename T>
10688  {
10689  typedef T type;
10690 
10691  interval_inserter(const std::size_t& interval, const T& t)
10692  : count_(0),
10693  interval_(interval),
10694  t_(t)
10695  {}
10696 
10697  inline bool operator()(const type&)
10698  {
10699  if (++count_ == interval_)
10700  {
10701  count_ = 0;
10702  return true;
10703  }
10704  else
10705  return false;
10706  }
10707 
10708  inline T operator()()
10709  {
10710  return t_;
10711  }
10712 
10713  private:
10714 
10715  std::size_t count_;
10716  std::size_t interval_;
10717  T t_;
10718  };
10719 
10720  template <typename Inserter,
10721  typename InputIterator,
10722  typename OutputIterator>
10723  inline std::size_t inserter(Inserter ins,
10724  const InputIterator begin, const InputIterator end,
10725  OutputIterator out)
10726  {
10727  std::size_t size = 0;
10728  InputIterator itr = begin;
10729  while (end != itr)
10730  {
10731  (*out) = (*itr);
10732  ++out;
10733  if (ins(*itr++))
10734  {
10735  (*out) = ins();
10736  ++out;
10737  size += 2;
10738  }
10739  else
10740  ++size;
10741  }
10742  return size;
10743  }
10744 
10745  template <typename Iterator, typename T>
10746  inline void iota(Iterator begin, Iterator end, T value)
10747  {
10748  Iterator itr = begin;
10749  while (end != itr)
10750  {
10751  (*itr) = value++;
10752  ++itr;
10753  }
10754  }
10755 
10756  template <typename T>
10757  inline void iota(typename range::adapter<T>& r, T value)
10758  {
10759  iota(r.begin(),r.end(),value);
10760  }
10761 
10762  template <typename T,
10763  typename Allocator,
10764  template <typename,typename> class Sequence>
10765  inline void iota(Sequence<T,Allocator>& sequence, std::size_t count, T value)
10766  {
10767  while (count)
10768  {
10769  sequence.push_back(value++);
10770  --count;
10771  }
10772  }
10773 
10774  template <typename T,
10775  typename Comparator,
10776  typename Allocator>
10777  inline void iota(std::set<T,Comparator,Allocator>& set, std::size_t count, T value)
10778  {
10779  while (count)
10780  {
10781  set.insert(value++);
10782  --count;
10783  }
10784  }
10785 
10786  template <typename T,
10787  typename Comparator,
10788  typename Allocator>
10789  inline void iota(std::multiset<T,Comparator,Allocator>& multiset, std::size_t count, T value)
10790  {
10791  while (count)
10792  {
10793  multiset.insert(value++);
10794  --count;
10795  }
10796  }
10797 
10798  template <typename OutputIterator, typename T>
10799  inline void iota(std::size_t count, T value, OutputIterator out)
10800  {
10801  while (count)
10802  {
10803  (*out) = value++;
10804  ++out;
10805  --count;
10806  }
10807  }
10808 
10809  template <typename T,
10810  typename Allocator,
10811  template <typename,typename> class Sequence>
10812  inline void iota(Sequence<T,Allocator>& sequence, const T& value)
10813  {
10814  strtk::iota(sequence.begin(),sequence.end(),value);
10815  }
10816 
10817  template <typename T,
10818  typename Comparator,
10819  typename Allocator>
10820  inline void iota(std::set<T,Comparator,Allocator>& set, const T& value)
10821  {
10822  strtk::iota(set.begin(),set.end(),value);
10823  }
10824 
10825  template <typename T,
10826  typename Comparator,
10827  typename Allocator>
10828  inline void iota(std::multiset<T,Comparator,Allocator>& multiset, const T& value)
10829  {
10830  strtk::iota(multiset.begin(),multiset.end(),value);
10831  }
10832 
10833  template <typename InputIterator, typename OutputIterator>
10834  inline void cut(const std::size_t& r0, const std::size_t& r1,
10835  const InputIterator begin, InputIterator end,
10836  OutputIterator out)
10837  {
10838  // static assert: InputIterator must be of type std::string
10839  InputIterator itr = begin;
10840  while (end != itr)
10841  {
10842  const std::string& s = (*itr);
10843  ++itr;
10844  if (s.size() < r0)
10845  continue;
10846  (*out++) = s.substr(r0,std::min(r1,s.size()) - r0);
10847  }
10848  }
10849 
10850  template <typename Allocator,
10851  template <typename,typename> class Sequence,
10852  typename OutputIterator>
10853  inline void cut(const std::size_t& r0, const std::size_t& r1,
10854  const Sequence<std::string, Allocator>& sequence,
10855  OutputIterator out)
10856  {
10857  cut(r0,r1,sequence.begin(),sequence.end(),out);
10858  }
10859 
10860  template <typename Iterator>
10861  inline void cut_inplace(const std::size_t& r0, const std::size_t& r1,
10862  const Iterator begin, const Iterator end)
10863  {
10864  // static assert: InputIterator must be of type std::string
10865  Iterator itr = begin;
10866  while (end != itr)
10867  {
10868  if ((*itr).size() >= r0)
10869  {
10870  (*itr) = (*itr).substr(r0,std::min(r1,(*itr).size()) - r0);
10871  }
10872  ++itr;
10873  }
10874  }
10875 
10876  template <typename Allocator,
10877  template <typename,typename> class Sequence>
10878  inline void cut(const std::size_t& r0, const std::size_t& r1,
10879  const Sequence<std::string, Allocator>& sequence)
10880  {
10881  cut(r0,r1,sequence.begin(),sequence.end());
10882  }
10883 
10884  template <typename Comparator, typename Allocator>
10885  inline void cut(const std::size_t& r0, const std::size_t& r1,
10886  const std::set<std::string, Comparator, Allocator>& set)
10887  {
10888  cut(r0,r1,set.begin(),set.end());
10889  }
10890 
10891  template <typename Comparator, typename Allocator>
10892  inline void cut(const std::size_t& r0, const std::size_t& r1,
10893  const std::multiset<std::string, Comparator, Allocator>& multiset)
10894  {
10895  cut(r0,r1,multiset.begin(),multiset.end());
10896  }
10897 
10899  {
10900  public:
10901 
10902  translation_table(const std::string& itable, const std::string& otable)
10903  {
10904  if (itable.size() != otable.size())
10905  {
10906  throw std::runtime_error("translation_table() - Input/Output table size mismatch.");
10907  }
10908  strtk::iota(table_, table_ + 256, static_cast<unsigned char>(0));
10909  for (std::size_t i = 0; i < itable.size(); ++i)
10910  {
10911  table_[static_cast<unsigned int>(itable[i])] = static_cast<unsigned char>(otable[i]);
10912  }
10913  }
10914 
10915  inline char operator()(const char c) const
10916  {
10917  return static_cast<char>(table_[static_cast<unsigned int>(c)]);
10918  }
10919 
10920  inline unsigned char operator()(const unsigned char c) const
10921  {
10922  return static_cast<unsigned char>(table_[static_cast<unsigned int>(c)]);
10923  }
10924 
10925  private:
10926 
10927  unsigned char table_[256];
10928  };
10929 
10930  inline std::string translate(const translation_table& trans_table, const std::string& s)
10931  {
10932  std::string result = s;
10933  std::transform(result.begin(),result.end(),result.begin(),trans_table);
10934  return result;
10935  }
10936 
10937  inline void translate_inplace(const translation_table& trans_table, std::string& s)
10938  {
10939  std::transform(s.begin(),s.end(),s.begin(),trans_table);
10940  }
10941 
10942  #ifdef strtk_enable_random
10943  inline void generate_random_data(unsigned char* data,
10944  std::size_t length,
10945  unsigned int pre_gen_cnt = 0,
10946  unsigned int seed = magic_seed)
10947  {
10948  boost::mt19937 rng(static_cast<boost::mt19937::result_type>(seed));
10949  boost::uniform_int<unsigned int> dist(std::numeric_limits<unsigned int>::min(),std::numeric_limits<unsigned int>::max());
10950  boost::variate_generator<boost::mt19937&, boost::uniform_int<unsigned int> > rnd(rng,dist);
10951 
10952  if (pre_gen_cnt > 0)
10953  {
10954  while (pre_gen_cnt--) rnd();
10955  }
10956 
10957  unsigned char* itr = data;
10958  unsigned int* x = 0;
10959  while (length >= sizeof(unsigned int))
10960  {
10961  x = reinterpret_cast<unsigned int*>(itr);
10962  (*x) = rnd();
10963  itr += sizeof(unsigned int);
10964  length -= sizeof(unsigned int);
10965  }
10966 
10967  if (length > 0)
10968  {
10969  itr -= (sizeof(unsigned int) - length);
10970  x = reinterpret_cast<unsigned int*>(itr);
10971  (*x) = rnd();
10972  }
10973  }
10974 
10975  namespace details
10976  {
10979 
10980  template <typename T> struct supported_random_type {};
10981 
10982  #define strtk_register_rand_int_type_tag(T)\
10983  template<> struct supported_random_type<T> { typedef rand_int_type_tag type; enum { value = true }; };
10984 
10985  #define strtk_register_rand_real_type_tag(T)\
10986  template<> struct supported_random_type<T> { typedef rand_real_type_tag type; enum { value = true }; };
10987 
10989  strtk_register_rand_int_type_tag(unsigned char)
10990 
10994  strtk_register_rand_int_type_tag(unsigned short)
10995  strtk_register_rand_int_type_tag(unsigned int)
10996  strtk_register_rand_int_type_tag(unsigned long)
10997 
11001 
11002  #undef strtk_register_rand_int_type_tag
11003  #undef strtk_register_rand_real_type_tag
11004 
11005  template <typename T, typename OutputIterator, typename RandomNumberGenerator>
11006  inline void generate_random_values_impl(const std::size_t& count,
11007  const T& min,
11008  const T& max,
11009  OutputIterator out,
11010  RandomNumberGenerator& rng,
11012  {
11013  // Note: The implied range will be: [min,max]
11014  using namespace boost;
11015  variate_generator<RandomNumberGenerator&,uniform_int<T> > rnd(rng,uniform_int<T>(min,max));
11016  for (std::size_t i = 0; i < count; ++i, *out++ = rnd()) ;
11017  }
11018 
11019  template <typename T, typename OutputIterator, typename RandomNumberGenerator>
11020  inline void generate_random_values_impl(const std::size_t& count,
11021  const T& min,
11022  const T& max,
11023  OutputIterator out,
11024  RandomNumberGenerator& rng,
11026  {
11027  // Note: The implied range will be: [min,max)
11028  using namespace boost;
11029  variate_generator<RandomNumberGenerator&, uniform_real<T> > rnd(rng,uniform_real<T>(min,max));
11030  for (std::size_t i = 0; i < count; ++i, *out++ = rnd()) ;
11031  }
11032 
11033  } // namespace details
11034 
11036  {
11037  private:
11038 
11039  typedef boost::mt19937 rng_type;
11040  typedef boost::variate_generator<rng_type, boost::uniform_real<double> > variate_type;
11041 
11042  public:
11043 
11044  uniform_real_rng(const std::size_t& seed = magic_seed,
11045  std::size_t pregen = 0)
11046  : rng_(static_cast<rng_type::result_type>(seed)),
11047  rnd_(rng_,boost::uniform_real<double>(0.0,1.0))
11048  {
11049  while (pregen--) rng_();
11050  }
11051 
11052  inline double operator()()
11053  {
11054  return rnd_();
11055  }
11056 
11057  private:
11058 
11059  rng_type rng_;
11060  variate_type rnd_;
11061  };
11062 
11063  template <typename T, typename OutputIterator>
11064  inline void generate_random_values(const std::size_t& count,
11065  const T& min,
11066  const T& max,
11067  OutputIterator out,
11068  const std::size_t& seed = magic_seed,
11069  const std::size_t& pregen = 0)
11070  {
11072  boost::mt19937 rng(static_cast<boost::mt19937::result_type>(seed));
11073  for (std::size_t i = 0; i++ < pregen; rng()) ;
11074  generate_random_values_impl(count,min,max,out,rng,type);
11075  }
11076 
11077  template <typename T,
11078  typename Allocator,
11079  template <typename,typename> class Sequence>
11080  inline void generate_random_values(const std::size_t& count,
11081  const T& min,
11082  const T& max,
11083  Sequence<T,Allocator>& sequence,
11084  const std::size_t& seed = magic_seed,
11085  const std::size_t& pregen = 0)
11086  {
11088  boost::mt19937 rng(static_cast<boost::mt19937::result_type>(seed));
11089  for (std::size_t i = 0; i++ < pregen; rng()) ;
11090  generate_random_values_impl(count,min,max,std::back_inserter(sequence),rng,type);
11091  }
11092 
11093  template <typename Iterator,
11094  typename RandomNumberGenerator,
11095  typename OutputIterator>
11096  inline void random_permutation(const Iterator begin, const Iterator end,
11097  RandomNumberGenerator& rng,
11098  OutputIterator out)
11099  {
11100  const std::size_t size = std::distance(begin,end);
11101  if ((rng. min() < 0.0) || (rng.max() > 1.0)) return;
11102  std::deque<std::size_t> index;
11103  for (std::size_t i = 0; i < size; index.push_back(i++)) ;
11104  while (!index.empty())
11105  {
11106  std::size_t idx = static_cast<std::size_t>(index.size() * rng());
11107  (*out) = *(begin + index[idx]);
11108  index.erase(index.begin() + idx);
11109  ++out;
11110  }
11111  }
11112 
11113  template <typename Iterator,
11114  typename OutputIterator>
11115  inline void random_permutation(const Iterator begin, const Iterator end,
11116  OutputIterator out,
11117  const std::size_t& seed = magic_seed,
11118  const std::size_t& pregen = 0)
11119  {
11120  boost::mt19937 rng(static_cast<boost::mt19937::result_type>(seed));
11121  for (std::size_t i = 0; i++ < pregen; rng()) ;
11122  boost::uniform_real<double> dist(0.0,1.0);
11123  boost::variate_generator<boost::mt19937&, boost::uniform_real<double> > rnd(rng,dist);
11124  random_permutation(begin,end,rnd,out);
11125  }
11126 
11127  template <typename T,
11128  typename Allocator,
11129  template <typename,typename> class Sequence,
11130  typename OutputIterator>
11131  inline void random_permutation(const Sequence<T,Allocator>& sequence,
11132  OutputIterator out,
11133  const std::size_t& seed = magic_seed,
11134  const std::size_t& pregen = 0)
11135  {
11136  random_permutation(sequence.begin(),sequence.end(),out,seed,pregen);
11137  }
11138 
11139  template <typename Iterator,
11140  typename RandomNumberGenerator,
11141  typename OutputIterator>
11142  inline bool random_combination(const Iterator begin, const Iterator end,
11143  std::size_t set_size,
11144  RandomNumberGenerator& rng,
11145  OutputIterator out)
11146  {
11147  const std::size_t size = std::distance(begin,end);
11148  if ((size < set_size) || (rng. min() < 0.0) || (rng.max() > 1.0)) return false;
11149  std::deque<std::size_t> index;
11150  for (std::size_t i = 0; i < size; index.push_back(i++)) ;
11151  while (set_size)
11152  {
11153  std::size_t idx = static_cast<std::size_t>(index.size() * rng());
11154  (*out) = *(begin + index[idx]);
11155  index.erase(index.begin() + idx);
11156  ++out;
11157  --set_size;
11158  }
11159  return true;
11160  }
11161 
11162  template <typename Iterator,
11163  typename OutputIterator>
11164  inline void random_combination(const Iterator begin, const Iterator end,
11165  const std::size_t& set_size,
11166  OutputIterator out,
11167  const std::size_t& seed = magic_seed,
11168  const std::size_t& pregen = 0)
11169  {
11170  boost::mt19937 rng(static_cast<boost::mt19937::result_type>(seed));
11171  for (std::size_t i = 0; i++ < pregen; rng()) ;
11172  boost::uniform_real<double> dist(0.0,1.0);
11173  boost::variate_generator<boost::mt19937&, boost::uniform_real<double> > rnd(rng,dist);
11174  random_combination(begin,end,set_size,rnd,out);
11175  }
11176 
11177  template <typename T,
11178  typename Allocator,
11179  template <typename,typename> class Sequence,
11180  typename OutputIterator>
11181  inline void random_combination(const Sequence<T,Allocator>& sequence,
11182  const std::size_t& set_size,
11183  OutputIterator out,
11184  const std::size_t& seed = magic_seed,
11185  const std::size_t& pregen = 0)
11186  {
11187  random_combination(sequence.begin(),sequence.end(),set_size,out,seed,pregen);
11188  }
11189 
11190  template <typename Iterator,
11191  typename OutputIterator,
11192  typename RandomNumberGenerator>
11193  inline std::size_t select_k_randomly(const Iterator begin, const Iterator end,
11194  const std::size_t k,
11195  OutputIterator out,
11196  RandomNumberGenerator& rng)
11197  {
11198  typedef typename std::iterator_traits<Iterator>::value_type T;
11199  std::vector<T> selection;
11200  selection.resize(k);
11201  Iterator itr = begin;
11202  std::size_t index = 0;
11203  while ((index < k) && (end != itr))
11204  {
11205  selection[index] = (*itr);
11206  ++index;
11207  ++itr;
11208  }
11209  if (0 == index)
11210  return 0;
11211  else if (index < k)
11212  {
11213  std::copy(selection.begin(),selection.begin() + index, out);
11214  return index;
11215  }
11216  double n = k + 1;
11217  while (end != itr)
11218  {
11219  if (rng() < (k / n))
11220  {
11221  selection[static_cast<std::size_t>(rng() * k)] = (*itr);
11222  }
11223  ++itr;
11224  ++n;
11225  }
11226  std::copy(selection.begin(),selection.end(),out);
11227  return k;
11228  }
11229 
11230  template <typename Iterator,
11231  typename OutputIterator,
11232  typename RandomNumberGenerator>
11233  inline void select_1_randomly(const Iterator begin, const Iterator end,
11234  OutputIterator out,
11235  RandomNumberGenerator& rng)
11236  {
11237  typedef typename std::iterator_traits<Iterator>::value_type T;
11238  T selection;
11239  if (begin == end)
11240  return;
11241  Iterator itr = begin;
11242  std::size_t n = 0;
11243  while (end != itr)
11244  {
11245  if (rng() < (1.0 / ++n))
11246  {
11247  selection = (*itr);
11248  }
11249  ++itr;
11250  }
11251  (*out) = selection;
11252  ++out;
11253  }
11254  #endif // strtk_enable_random
11255 
11256  template <typename Iterator>
11257  inline bool next_combination(const Iterator first, Iterator k, const Iterator last)
11258  {
11259  /* Credits: Thomas Draper */
11260  if ((first == last) || (first == k) || (last == k))
11261  return false;
11262  Iterator itr1 = first;
11263  Iterator itr2 = last;
11264  ++itr1;
11265  if (last == itr1)
11266  return false;
11267  itr1 = last;
11268  --itr1;
11269  itr1 = k;
11270  --itr2;
11271  while (first != itr1)
11272  {
11273  if (*--itr1 < (*itr2))
11274  {
11275  Iterator j = k;
11276  while (!((*itr1) < (*j))) ++j;
11277  std::iter_swap(itr1,j);
11278  ++itr1;
11279  ++j;
11280  itr2 = k;
11281  std::rotate(itr1,j,last);
11282  while (last != j)
11283  {
11284  ++j;
11285  ++itr2;
11286  }
11287  std::rotate(k,itr2,last);
11288  return true;
11289  }
11290  }
11291  std::rotate(first,k,last);
11292  return false;
11293  }
11294 
11295  template <typename T,
11296  typename Allocator,
11297  template <typename,typename> class Sequence>
11298  inline bool next_combination(Sequence<T,Allocator>& sequence, const std::size_t& size)
11299  {
11300  return next_combination(sequence.begin(), sequence.begin() + size, sequence.end());
11301  }
11302 
11303  template <typename Iterator, typename Function>
11304  inline void for_each_permutation(Iterator begin, Iterator end, Function function)
11305  {
11306  do
11307  {
11308  function(begin,end);
11309  }
11310  while (std::next_permutation(begin,end));
11311  }
11312 
11313  template <typename Iterator, typename Function>
11314  inline bool for_each_permutation_conditional(Iterator begin, Iterator end, Function function)
11315  {
11316  do
11317  {
11318  if (!function(begin,end))
11319  return false;
11320  }
11321  while (std::next_permutation(begin,end));
11322  return true;
11323  }
11324 
11325  namespace details
11326  {
11327  /*
11328  Credits:
11329  (C) Copyright Howard Hinnant 2005-2011.
11330  Use, modification and distribution are subject to the Boost Software License,
11331  Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
11332  http://www.boost.org/LICENSE_1_0.txt).
11333  */
11334  template <typename Iterator>
11335  static inline void rotate_discontinuous(Iterator first1, Iterator last1,
11336  typename std::iterator_traits<Iterator>::difference_type d1,
11337  Iterator first2, Iterator last2,
11338  typename std::iterator_traits<Iterator>::difference_type d2)
11339  {
11340  using std::swap;
11341  if (d1 <= d2)
11342  std::rotate(first2, std::swap_ranges(first1, last1, first2), last2);
11343  else
11344  {
11345  Iterator i1 = last1;
11346  while (first2 != last2)
11347  {
11348  swap(*--i1,*--last2);
11349  }
11350  std::rotate(first1, i1, last1);
11351  }
11352  }
11353 
11354  template <typename Iterator, class Function>
11355  inline void combine_discontinuous(Iterator first1, Iterator last1, typename std::iterator_traits<Iterator>::difference_type d1,
11356  Iterator first2, Iterator last2, typename std::iterator_traits<Iterator>::difference_type d2,
11357  Function& f,
11358  typename std::iterator_traits<Iterator>::difference_type d = 0)
11359  {
11360  typedef typename std::iterator_traits<Iterator>::difference_type D;
11361  using std::swap;
11362  if ((0 == d1) || (0 == d2))
11363  return f();
11364  if (1 == d1)
11365  {
11366  Iterator i2 = first2;
11367  while (i2 != last2)
11368  {
11369  f();
11370  swap(*first1, *i2);
11371  ++i2;
11372  }
11373  }
11374  else
11375  {
11376  Iterator f1p = first1;
11377  std::advance(f1p,1);
11378  Iterator i2 = first2;
11379  D d22 = d2;
11380  while (i2 != last2)
11381  {
11382  combine_discontinuous(f1p, last1, d1 - 1, i2, last2, d22, f, d + 1);
11383  swap(*first1, *i2);
11384  ++i2;
11385  --d22;
11386  }
11387  }
11388  f();
11389  if (0 != d)
11390  {
11391  Iterator f2p = first2;
11392  std::advance(f2p,1);
11393  rotate_discontinuous(first1, last1, d1, f2p, last2, d2 - 1);
11394  }
11395  else
11396  rotate_discontinuous(first1, last1, d1, first2, last2, d2);
11397  }
11398 
11399  template <typename Iterator, class Function>
11400  inline bool combine_discontinuous_conditional(Iterator first1, Iterator last1, typename std::iterator_traits<Iterator>::difference_type d1,
11401  Iterator first2, Iterator last2, typename std::iterator_traits<Iterator>::difference_type d2,
11402  Function& f,
11403  typename std::iterator_traits<Iterator>::difference_type d = 0)
11404  {
11405  typedef typename std::iterator_traits<Iterator>::difference_type D;
11406  using std::swap;
11407  if (d1 == 0 || d2 == 0)
11408  return f();
11409  if (d1 == 1)
11410  {
11411  for (Iterator i2 = first2; i2 != last2; ++i2)
11412  {
11413  if (!f())
11414  return false;
11415  swap(*first1, *i2);
11416  }
11417  }
11418  else
11419  {
11420  Iterator f1p = first1;
11421  std::advance(f1p,1);
11422  Iterator i2 = first2;
11423  for (D d22 = d2; i2 != last2; ++i2, --d22)
11424  {
11425  if (!combine_discontinuous_conditional(f1p, last1, d1-1, i2, last2, d22, f, d + 1))
11426  return false;
11427  swap(*first1, *i2);
11428  }
11429  }
11430  if (!f())
11431  return false;
11432  if (d != 0)
11433  {
11434  Iterator f2p = first2;
11435  std::advance(f2p,1);
11436  rotate_discontinuous(first1, last1, d1, f2p, last2, d2 - 1);
11437  }
11438  else
11439  rotate_discontinuous(first1, last1, d1, first2, last2, d2);
11440  return true;
11441  }
11442 
11443  template <class Function, typename Iterator>
11445  {
11446  public:
11447 
11448  bound_range(Function f, Iterator first, Iterator last)
11449  : f_(f),
11450  first_(first),
11451  last_(last)
11452  {}
11453 
11454  inline void operator()()
11455  {
11456  f_(first_,last_);
11457  }
11458 
11459  private:
11460 
11461  inline bound_range& operator=(const bound_range&);
11462 
11463  Function f_;
11464  Iterator first_;
11465  Iterator last_;
11466  };
11467 
11468  template <class Function, typename Iterator>
11470  {
11471  public:
11472 
11473  bound_range_conditional(Function f, Iterator first, Iterator last)
11474  : f_(f),
11475  first_(first),
11476  last_(last)
11477  {}
11478 
11479  inline bool operator()()
11480  {
11481  return f_(first_,last_);
11482  }
11483 
11484  private:
11485 
11486  inline bound_range_conditional& operator=(const bound_range_conditional&);
11487 
11488  Function f_;
11489  Iterator first_;
11490  Iterator last_;
11491  };
11492 
11493  }
11494 
11495  template <typename Iterator, typename Function>
11496  inline void for_each_combination(Iterator begin, Iterator end,
11497  const std::size_t& size,
11498  Function function)
11499  {
11500  if (static_cast<typename std::iterator_traits<Iterator>::difference_type>(size) > std::distance(begin,end))
11501  return;
11502  Iterator mid = begin + size;
11503  details::bound_range<Function&, Iterator> func(function,begin,mid);
11504  details::combine_discontinuous(begin, mid,
11505  std::distance(begin,mid),
11506  mid, end,
11507  std::distance(mid,end),
11508  func);
11509  }
11510 
11511  template <typename Iterator, typename Function>
11512  inline void for_each_combination_conditional(Iterator begin, Iterator end,
11513  const std::size_t& size,
11514  Function function)
11515  {
11516  if (static_cast<typename std::iterator_traits<Iterator>::difference_type>(size) > std::distance(begin,end))
11517  return;
11518  Iterator mid = begin + size;
11521  std::distance(begin,mid),
11522  mid, end,
11523  std::distance(mid,end),
11524  func);
11525  }
11526 
11527  inline unsigned long long int n_choose_k(const unsigned long long int& n, const unsigned long long int& k)
11528  {
11529  if (n < k) return 0;
11530  if (0 == n) return 0;
11531  if (0 == k) return 1;
11532  if (n == k) return 1;
11533  if (1 == k) return n;
11534 
11535  typedef unsigned long long int value_type;
11536 
11537  class n_choose_k_impl
11538  {
11539  public:
11540 
11541  n_choose_k_impl(value_type* table, const value_type& dimension)
11542  : table_(table),
11543  dimension_(dimension / 2)
11544  {}
11545 
11546  inline value_type& lookup(const value_type& n, const value_type& k)
11547  {
11548  const std::size_t difference = static_cast<std::size_t>(n - k);
11549  return table_[static_cast<std::size_t>((dimension_ * n) + std::min<value_type>(k,difference))];
11550  }
11551 
11552  inline value_type compute(const value_type& n, const value_type& k)
11553  {
11554  // n-Choose-k = (n-1)-Choose-(k-1) + (n-1)-Choose-k
11555  if ((0 == k) || (k == n))
11556  return 1;
11557  value_type v1 = lookup(n - 1,k - 1);
11558  if (0 == v1)
11559  v1 = lookup(n - 1,k - 1) = compute(n - 1,k - 1);
11560  value_type v2 = lookup(n - 1,k);
11561  if (0 == v2)
11562  v2 = lookup(n - 1,k) = compute(n - 1,k);
11563  return v1 + v2;
11564  }
11565 
11566  value_type* table_;
11567  const value_type dimension_;
11568 
11569  private:
11570 
11571  inline n_choose_k_impl& operator=(const n_choose_k_impl&)
11572  {
11573  return *this;
11574  }
11575  };
11576 
11577  static const std::size_t static_table_dim = 100;
11578  static const std::size_t static_table_size = static_cast<std::size_t>((static_table_dim * static_table_dim) / 2);
11579  static value_type static_table[static_table_size];
11580  static bool static_table_initialized = false;
11581 
11582  if (!static_table_initialized && (n <= static_table_dim))
11583  {
11584  std::fill_n(static_table,static_table_size,0);
11585  static_table_initialized = true;
11586  }
11587 
11588  const std::size_t table_size = static_cast<std::size_t>(n * (n / 2) + (n & 1));
11589 
11590  unsigned long long int dimension = static_table_dim;
11591  value_type* table = 0;
11592 
11593  if (table_size <= static_table_size)
11594  table = static_table;
11595  else
11596  {
11597  dimension = n;
11598  table = new value_type[table_size];
11599  std::fill_n(table,table_size,0ULL);
11600  }
11601 
11602  value_type result = n_choose_k_impl(table,dimension).compute(n,k);
11603 
11604  if (table != static_table)
11605  delete [] table;
11606 
11607  return result;
11608  }
11609 
11611  {
11612  const unsigned long long int max_n = 100ULL;
11613  for (unsigned long long int n = 0; n < max_n; ++n)
11614  {
11615  for (unsigned long long int k = 0; k < max_n; ++k)
11616  {
11617  n_choose_k(n,k);
11618  }
11619  }
11620  }
11621 
11622  template <typename OutputIterator>
11623  inline void nth_combination_sequence(unsigned long long int n,
11624  const std::size_t& r,
11625  const std::size_t& k,
11626  OutputIterator out,
11627  const bool complete_index = true)
11628  {
11629  //Compute the indicies for the n'th combination of r-choose-k
11630  //n must be in the range [0,r-choose-k)
11631  typedef unsigned long long int value_type;
11632 
11633  std::vector<std::size_t> index_list(k,0);
11634  value_type j = 0;
11635  value_type x = 0;
11636  ++n;
11637 
11638  for (std::size_t i = 1; i <= (k - 1); ++i)
11639  {
11640  index_list[i - 1] = 0;
11641  if (1 < i)
11642  {
11643  index_list[i - 1] = index_list[i - 2];
11644  }
11645 
11646  do
11647  {
11648  index_list[i - 1] += 1;
11649  j = n_choose_k(r - index_list[i - 1], k - i);
11650  x += j;
11651  }
11652  while (n > x);
11653  x -= j;
11654  }
11655 
11656  index_list[k - 1] = index_list[k - 2] + static_cast<std::size_t>(n) - static_cast<std::size_t>(x);
11657  for (std::size_t i = 0; i < index_list.size(); --index_list[i++]);
11658 
11659  std::copy(index_list.begin(),index_list.end(),out);
11660 
11661  if (complete_index)
11662  {
11663  std::vector<unsigned int> exist_table(r,0);
11664 
11665  for (std::size_t i = 0; i < index_list.size(); ++i)
11666  {
11667  exist_table[index_list[i]] = 1;
11668  }
11669 
11670  for (std::size_t i = 0; i < exist_table.size(); ++i)
11671  {
11672  if (0 == exist_table[i])
11673  {
11674  (*out) = i;
11675  ++out;
11676  }
11677  }
11678  }
11679  }
11680 
11681  template <typename InputIterator, typename OutputIterator>
11682  inline void nth_combination_sequence(const std::size_t& n,
11683  const std::size_t& k,
11684  const InputIterator begin,
11685  const InputIterator end,
11686  OutputIterator out,
11687  const bool complete_index = true)
11688  {
11689  const std::size_t length = std::distance(begin,end);
11690  std::vector<std::size_t> index_list;
11691  nth_combination_sequence(n,length,k,std::back_inserter(index_list),complete_index);
11692  for (std::size_t i = 0; i < index_list.size(); ++i)
11693  {
11694  (*out) = *(begin + index_list[i]);
11695  ++out;
11696  }
11697  }
11698 
11699  template <typename OutputIterator>
11700  inline void nth_permutation_sequence(std::size_t n, const std::size_t k, OutputIterator out)
11701  {
11702  //Note: n in [0,k!)
11703  std::vector<std::size_t> factorid (k,0);
11704  std::vector<std::size_t> permutate(k,0);
11705 
11706  factorid[0] = 1;
11707  for (std::size_t i = 1; i < k; ++i)
11708  {
11709  factorid[i] = factorid[i - 1] * i;
11710  }
11711 
11712  for (std::size_t i = 0; i < k; ++i)
11713  {
11714  permutate[i] = n / factorid[k - i - 1];
11715  n = n % factorid[k - i - 1];
11716  }
11717 
11718  for (std::size_t i = k - 1; i > 0; --i)
11719  {
11720  for (int j = static_cast<int>(i - 1); j >= 0; --j)
11721  {
11722  if (permutate[j] <= permutate[i])
11723  {
11724  ++permutate[i];
11725  }
11726  }
11727  }
11728 
11729  for (std::size_t i = 0; i < k; ++i)
11730  {
11731  *(out++) = permutate[i];
11732  }
11733  }
11734 
11735  template <typename InputIterator, typename OutputIterator>
11736  inline void nth_permutation_sequence(std::size_t n,
11737  const InputIterator begin,
11738  const InputIterator end,
11739  OutputIterator out)
11740  {
11741  const std::size_t size = std::distance(begin,end);
11742  std::vector<std::size_t> index_list(size,0);
11743  nth_permutation_sequence(n,size,index_list.begin());
11744  for (std::size_t i = 0; i < size; ++i)
11745  {
11746  *(out++) = (begin + index_list[i]);
11747  }
11748  }
11749 
11750  inline std::string nth_permutation_sequence(const std::size_t& n, const std::string& s)
11751  {
11752  std::vector<std::size_t> index_list(s.size(),0);
11753  nth_permutation_sequence(n,s.size(),index_list.begin());
11754  std::string result;
11755  result.reserve(s.size());
11756  for (std::size_t i = 0; i < index_list.size(); ++i)
11757  {
11758  result += s[index_list[i]];
11759  }
11760  return result;
11761  }
11762 
11763  template <typename Iterator>
11764  class combination_iterator : public std::iterator<std::forward_iterator_tag,
11765  std::pair<Iterator,Iterator>,
11766  void,
11767  void>
11768  {
11769  public:
11770 
11771  typedef Iterator iterator;
11772  typedef const iterator const_iterator;
11773  typedef std::pair<Iterator,Iterator> range_type;
11774 
11775  explicit inline combination_iterator(const std::size_t& k,
11776  iterator begin, iterator end,
11777  const bool sorted = true)
11778  : begin_(begin),
11779  end_(end),
11780  middle_(begin + k),
11781  current_combination_(begin_,middle_)
11782  {
11783  if (!sorted)
11784  {
11785  std::sort(begin,end);
11786  }
11787  }
11788 
11789  template <typename T,
11790  typename Allocator,
11791  template <typename,typename> class Sequence>
11792  explicit inline combination_iterator(const std::size_t& k,
11793  Sequence<T,Allocator>& seq,
11794  const bool sorted = true)
11795  : begin_(seq.begin()),
11796  end_(seq.end()),
11797  middle_(begin_ + k),
11798  current_combination_(begin_,middle_)
11799  {
11800  if (!sorted)
11801  {
11802  std::sort(begin_,end_);
11803  }
11804  }
11805 
11806  explicit inline combination_iterator(const std::size_t& k,
11807  std::string& str,
11808  const bool sorted = true)
11809  : begin_(const_cast<char*>(str.data())),
11810  end_(const_cast<char*>(str.data() + str.size())),
11811  middle_(begin_ + k),
11812  current_combination_(begin_,middle_)
11813  {
11814  if (!sorted)
11815  {
11816  std::sort(begin_,end_);
11817  }
11818  }
11819 
11821  : begin_(end),
11822  end_(end),
11823  middle_(end),
11824  current_combination_(end,end)
11825  {}
11826 
11828  : begin_(const_cast<char*>(str.data() + str.size())),
11829  end_(begin_),
11830  middle_(end_),
11831  current_combination_(end_,end_)
11832  {}
11833 
11834  template <typename T,
11835  typename Allocator,
11836  template <typename,typename> class Sequence>
11837  explicit inline combination_iterator(Sequence<T,Allocator>& seq)
11838  : begin_(seq.end()),
11839  end_(seq.end()),
11840  middle_(end_),
11841  current_combination_(end_,end_)
11842  {}
11843 
11845  {
11846  if (begin_ != end_)
11847  {
11848  if (!next_combination(begin_,middle_,end_))
11849  {
11850  begin_ = middle_ = end_;
11851  }
11852  }
11853  return (*this);
11854  }
11855 
11857  {
11858  combination_iterator tmp = *this;
11859  this->operator++();
11860  return tmp;
11861  }
11862 
11864  {
11865  if (inc > 0)
11866  {
11867  for (int i = 0; i < inc; ++i, ++(*this)) ;
11868  }
11869  return (*this);
11870  }
11871 
11872  inline range_type operator*() const
11873  {
11874  return current_combination_;
11875  }
11876 
11877  inline bool operator==(const combination_iterator& itr) const
11878  {
11879  return (begin_ == itr.begin_ ) &&
11880  (end_ == itr.end_ ) &&
11881  (middle_ == itr.middle_);
11882  }
11883 
11884  inline bool operator!=(const combination_iterator& itr) const
11885  {
11886  return !operator==(itr);
11887  }
11888 
11889  protected:
11890 
11895  };
11896 
11897  namespace fast
11898  {
11899  /*
11900  Note: The following routines perform no sanity checks at all
11901  upon the input data. Hence they should only be used with
11902  data that is known to be completely 'valid'.
11903  */
11904  namespace details
11905  {
11906 
11907  template <typename Iterator, int N>
11909  {
11910  static inline bool process(Iterator)
11911  {
11912  throw std::runtime_error("all_digits_check_impl - unsupported value for N.");
11913  }
11914  };
11915 
11916  template <typename Iterator>
11917  struct all_digits_check_impl<Iterator,19>
11918  {
11919  static inline bool process(Iterator itr)
11920  {
11921  return static_cast<unsigned char>(itr[0] - '0') < 10 &&
11923  }
11924  };
11925 
11926  template <typename Iterator>
11927  struct all_digits_check_impl<Iterator,18>
11928  {
11929  static inline bool process(Iterator itr)
11930  {
11931  return static_cast<unsigned char>(itr[0] - '0') < 10 &&
11933  }
11934  };
11935 
11936  template <typename Iterator>
11937  struct all_digits_check_impl<Iterator,17>
11938  {
11939  static inline bool process(Iterator itr)
11940  {
11941  return static_cast<unsigned char>(itr[0] - '0') < 10 &&
11943  }
11944  };
11945 
11946  template <typename Iterator>
11947  struct all_digits_check_impl<Iterator,16>
11948  {
11949  static inline bool process(Iterator itr)
11950  {
11951  return static_cast<unsigned char>(itr[ 0] - '0') < 10 &&
11952  static_cast<unsigned char>(itr[ 1] - '0') < 10 &&
11953  static_cast<unsigned char>(itr[ 2] - '0') < 10 &&
11954  static_cast<unsigned char>(itr[ 3] - '0') < 10 &&
11955  static_cast<unsigned char>(itr[ 4] - '0') < 10 &&
11956  static_cast<unsigned char>(itr[ 5] - '0') < 10 &&
11957  static_cast<unsigned char>(itr[ 6] - '0') < 10 &&
11958  static_cast<unsigned char>(itr[ 7] - '0') < 10 &&
11959  static_cast<unsigned char>(itr[ 8] - '0') < 10 &&
11960  static_cast<unsigned char>(itr[ 9] - '0') < 10 &&
11961  static_cast<unsigned char>(itr[10] - '0') < 10 &&
11962  static_cast<unsigned char>(itr[11] - '0') < 10 &&
11963  static_cast<unsigned char>(itr[12] - '0') < 10 &&
11964  static_cast<unsigned char>(itr[13] - '0') < 10 &&
11965  static_cast<unsigned char>(itr[14] - '0') < 10 &&
11966  static_cast<unsigned char>(itr[15] - '0') < 10;
11967  }
11968  };
11969 
11970  template <typename Iterator>
11971  struct all_digits_check_impl<Iterator,15>
11972  {
11973  static inline bool process(Iterator itr)
11974  {
11975  return static_cast<unsigned char>(itr[ 0] - '0') < 10 &&
11976  static_cast<unsigned char>(itr[ 1] - '0') < 10 &&
11977  static_cast<unsigned char>(itr[ 2] - '0') < 10 &&
11978  static_cast<unsigned char>(itr[ 3] - '0') < 10 &&
11979  static_cast<unsigned char>(itr[ 4] - '0') < 10 &&
11980  static_cast<unsigned char>(itr[ 5] - '0') < 10 &&
11981  static_cast<unsigned char>(itr[ 6] - '0') < 10 &&
11982  static_cast<unsigned char>(itr[ 7] - '0') < 10 &&
11983  static_cast<unsigned char>(itr[ 8] - '0') < 10 &&
11984  static_cast<unsigned char>(itr[ 9] - '0') < 10 &&
11985  static_cast<unsigned char>(itr[10] - '0') < 10 &&
11986  static_cast<unsigned char>(itr[11] - '0') < 10 &&
11987  static_cast<unsigned char>(itr[12] - '0') < 10 &&
11988  static_cast<unsigned char>(itr[13] - '0') < 10 &&
11989  static_cast<unsigned char>(itr[14] - '0') < 10;
11990  }
11991  };
11992 
11993  template <typename Iterator>
11994  struct all_digits_check_impl<Iterator,14>
11995  {
11996  static inline bool process(Iterator itr)
11997  {
11998  return static_cast<unsigned char>(itr[ 0] - '0') < 10 &&
11999  static_cast<unsigned char>(itr[ 1] - '0') < 10 &&
12000  static_cast<unsigned char>(itr[ 2] - '0') < 10 &&
12001  static_cast<unsigned char>(itr[ 3] - '0') < 10 &&
12002  static_cast<unsigned char>(itr[ 4] - '0') < 10 &&
12003  static_cast<unsigned char>(itr[ 5] - '0') < 10 &&
12004  static_cast<unsigned char>(itr[ 6] - '0') < 10 &&
12005  static_cast<unsigned char>(itr[ 7] - '0') < 10 &&
12006  static_cast<unsigned char>(itr[ 8] - '0') < 10 &&
12007  static_cast<unsigned char>(itr[ 9] - '0') < 10 &&
12008  static_cast<unsigned char>(itr[10] - '0') < 10 &&
12009  static_cast<unsigned char>(itr[11] - '0') < 10 &&
12010  static_cast<unsigned char>(itr[12] - '0') < 10 &&
12011  static_cast<unsigned char>(itr[13] - '0') < 10;
12012  }
12013  };
12014 
12015  template <typename Iterator>
12016  struct all_digits_check_impl<Iterator,13>
12017  {
12018  static inline bool process(Iterator itr)
12019  {
12020  return static_cast<unsigned char>(itr[ 0] - '0') < 10 &&
12021  static_cast<unsigned char>(itr[ 1] - '0') < 10 &&
12022  static_cast<unsigned char>(itr[ 2] - '0') < 10 &&
12023  static_cast<unsigned char>(itr[ 3] - '0') < 10 &&
12024  static_cast<unsigned char>(itr[ 4] - '0') < 10 &&
12025  static_cast<unsigned char>(itr[ 5] - '0') < 10 &&
12026  static_cast<unsigned char>(itr[ 6] - '0') < 10 &&
12027  static_cast<unsigned char>(itr[ 7] - '0') < 10 &&
12028  static_cast<unsigned char>(itr[ 8] - '0') < 10 &&
12029  static_cast<unsigned char>(itr[ 9] - '0') < 10 &&
12030  static_cast<unsigned char>(itr[10] - '0') < 10 &&
12031  static_cast<unsigned char>(itr[11] - '0') < 10 &&
12032  static_cast<unsigned char>(itr[12] - '0') < 10;
12033  }
12034  };
12035 
12036  template <typename Iterator>
12037  struct all_digits_check_impl<Iterator,12>
12038  {
12039  static inline bool process(Iterator itr)
12040  {
12041  return static_cast<unsigned char>(itr[ 0] - '0') < 10 &&
12042  static_cast<unsigned char>(itr[ 1] - '0') < 10 &&
12043  static_cast<unsigned char>(itr[ 2] - '0') < 10 &&
12044  static_cast<unsigned char>(itr[ 3] - '0') < 10 &&
12045  static_cast<unsigned char>(itr[ 4] - '0') < 10 &&
12046  static_cast<unsigned char>(itr[ 5] - '0') < 10 &&
12047  static_cast<unsigned char>(itr[ 6] - '0') < 10 &&
12048  static_cast<unsigned char>(itr[ 7] - '0') < 10 &&
12049  static_cast<unsigned char>(itr[ 8] - '0') < 10 &&
12050  static_cast<unsigned char>(itr[ 9] - '0') < 10 &&
12051  static_cast<unsigned char>(itr[10] - '0') < 10 &&
12052  static_cast<unsigned char>(itr[11] - '0') < 10;
12053  }
12054  };
12055 
12056  template <typename Iterator>
12057  struct all_digits_check_impl<Iterator,11>
12058  {
12059  static inline bool process(Iterator itr)
12060  {
12061  return static_cast<unsigned char>(itr[ 0] - '0') < 10 &&
12062  static_cast<unsigned char>(itr[ 1] - '0') < 10 &&
12063  static_cast<unsigned char>(itr[ 2] - '0') < 10 &&
12064  static_cast<unsigned char>(itr[ 3] - '0') < 10 &&
12065  static_cast<unsigned char>(itr[ 4] - '0') < 10 &&
12066  static_cast<unsigned char>(itr[ 5] - '0') < 10 &&
12067  static_cast<unsigned char>(itr[ 6] - '0') < 10 &&
12068  static_cast<unsigned char>(itr[ 7] - '0') < 10 &&
12069  static_cast<unsigned char>(itr[ 8] - '0') < 10 &&
12070  static_cast<unsigned char>(itr[ 9] - '0') < 10 &&
12071  static_cast<unsigned char>(itr[10] - '0') < 10;
12072  }
12073  };
12074 
12075  template <typename Iterator>
12076  struct all_digits_check_impl<Iterator,10>
12077  {
12078  static inline bool process(Iterator itr)
12079  {
12080  return static_cast<unsigned char>(itr[0] - '0') < 10 &&
12081  static_cast<unsigned char>(itr[1] - '0') < 10 &&
12082  static_cast<unsigned char>(itr[2] - '0') < 10 &&
12083  static_cast<unsigned char>(itr[3] - '0') < 10 &&
12084  static_cast<unsigned char>(itr[4] - '0') < 10 &&
12085  static_cast<unsigned char>(itr[5] - '0') < 10 &&
12086  static_cast<unsigned char>(itr[6] - '0') < 10 &&
12087  static_cast<unsigned char>(itr[7] - '0') < 10 &&
12088  static_cast<unsigned char>(itr[8] - '0') < 10 &&
12089  static_cast<unsigned char>(itr[9] - '0') < 10;
12090  }
12091  };
12092 
12093  template <typename Iterator>
12094  struct all_digits_check_impl<Iterator,9>
12095  {
12096  static inline bool process(Iterator itr)
12097  {
12098  return static_cast<unsigned char>(itr[0] - '0') < 10 &&
12099  static_cast<unsigned char>(itr[1] - '0') < 10 &&
12100  static_cast<unsigned char>(itr[2] - '0') < 10 &&
12101  static_cast<unsigned char>(itr[3] - '0') < 10 &&
12102  static_cast<unsigned char>(itr[4] - '0') < 10 &&
12103  static_cast<unsigned char>(itr[5] - '0') < 10 &&
12104  static_cast<unsigned char>(itr[6] - '0') < 10 &&
12105  static_cast<unsigned char>(itr[7] - '0') < 10 &&
12106  static_cast<unsigned char>(itr[8] - '0') < 10;
12107  }
12108  };
12109 
12110  template <typename Iterator>
12111  struct all_digits_check_impl<Iterator,8>
12112  {
12113  static inline bool process(Iterator itr)
12114  {
12115  return static_cast<unsigned char>(itr[0] - '0') < 10 &&
12116  static_cast<unsigned char>(itr[1] - '0') < 10 &&
12117  static_cast<unsigned char>(itr[2] - '0') < 10 &&
12118  static_cast<unsigned char>(itr[3] - '0') < 10 &&
12119  static_cast<unsigned char>(itr[4] - '0') < 10 &&
12120  static_cast<unsigned char>(itr[5] - '0') < 10 &&
12121  static_cast<unsigned char>(itr[6] - '0') < 10 &&
12122  static_cast<unsigned char>(itr[7] - '0') < 10;
12123  }
12124  };
12125 
12126  template <typename Iterator>
12127  struct all_digits_check_impl<Iterator,7>
12128  {
12129  static inline bool process(Iterator itr)
12130  {
12131  return static_cast<unsigned char>(itr[0] - '0') < 10 &&
12132  static_cast<unsigned char>(itr[1] - '0') < 10 &&
12133  static_cast<unsigned char>(itr[2] - '0') < 10 &&
12134  static_cast<unsigned char>(itr[3] - '0') < 10 &&
12135  static_cast<unsigned char>(itr[4] - '0') < 10 &&
12136  static_cast<unsigned char>(itr[5] - '0') < 10 &&
12137  static_cast<unsigned char>(itr[6] - '0') < 10;
12138  }
12139  };
12140 
12141  template <typename Iterator>
12142  struct all_digits_check_impl<Iterator,6>
12143  {
12144  static inline bool process(Iterator itr)
12145  {
12146  return static_cast<unsigned char>(itr[0] - '0') < 10 &&
12147  static_cast<unsigned char>(itr[1] - '0') < 10 &&
12148  static_cast<unsigned char>(itr[2] - '0') < 10 &&
12149  static_cast<unsigned char>(itr[3] - '0') < 10 &&
12150  static_cast<unsigned char>(itr[4] - '0') < 10 &&
12151  static_cast<unsigned char>(itr[5] - '0') < 10;
12152  }
12153  };
12154 
12155  template <typename Iterator>
12156  struct all_digits_check_impl<Iterator,5>
12157  {
12158  static inline bool process(Iterator itr)
12159  {
12160  return static_cast<unsigned char>(itr[0] - '0') < 10 &&
12161  static_cast<unsigned char>(itr[1] - '0') < 10 &&
12162  static_cast<unsigned char>(itr[2] - '0') < 10 &&
12163  static_cast<unsigned char>(itr[3] - '0') < 10 &&
12164  static_cast<unsigned char>(itr[4] - '0') < 10;
12165  }
12166  };
12167 
12168  template <typename Iterator>
12169  struct all_digits_check_impl<Iterator,4>
12170  {
12171  static inline bool process(Iterator itr)
12172  {
12173  return static_cast<unsigned char>(itr[0] - '0') < 10 &&
12174  static_cast<unsigned char>(itr[1] - '0') < 10 &&
12175  static_cast<unsigned char>(itr[2] - '0') < 10 &&
12176  static_cast<unsigned char>(itr[3] - '0') < 10;
12177  }
12178  };
12179 
12180  template <typename Iterator>
12181  struct all_digits_check_impl<Iterator,3>
12182  {
12183  static inline bool process(Iterator itr)
12184  {
12185  return
12186  static_cast<unsigned char>(itr[0] - '0') < 10 &&
12187  static_cast<unsigned char>(itr[1] - '0') < 10 &&
12188  static_cast<unsigned char>(itr[2] - '0') < 10;
12189  }
12190  };
12191 
12192  template <typename Iterator>
12193  struct all_digits_check_impl<Iterator,2>
12194  {
12195  static inline bool process(Iterator itr)
12196  {
12197  return static_cast<unsigned char>(itr[ 0] - '0') < 10 &&
12198  static_cast<unsigned char>(itr[ 1] - '0') < 10;
12199  }
12200  };
12201 
12202  template <typename Iterator>
12203  struct all_digits_check_impl<Iterator,1>
12204  {
12205  static inline bool process(Iterator itr)
12206  {
12207  return static_cast<unsigned char>(itr[ 0] - '0') < 10;
12208  }
12209  };
12210 
12211  template <typename Iterator>
12212  struct all_digits_check_impl<Iterator,0>
12213  {
12214  static inline bool process(Iterator)
12215  {
12216  return false;
12217  }
12218  };
12219 
12220  template <typename T, typename Iterator, int N>
12222  {
12223  static inline void process(Iterator, T&)
12224  { throw std::runtime_error("numeric_convert_impl::process( - unsupported value for N."); }
12225  };
12226 
12227  template <typename T, typename Iterator>
12228  struct numeric_convert_impl<T,Iterator,19>
12229  {
12230  static inline void process(Iterator itr, T& t)
12231  {
12233  t += static_cast<T>((itr[0] - '0') * 1000000000000000000LL);
12234  }
12235  };
12236 
12237  template <typename T, typename Iterator>
12238  struct numeric_convert_impl<T,Iterator,18>
12239  {
12240  static inline void process(Iterator itr, T& t)
12241  {
12243  t += static_cast<T>((itr[0] - '0') * 100000000000000000LL);
12244  }
12245  };
12246 
12247  template <typename T, typename Iterator>
12248  struct numeric_convert_impl<T,Iterator,17>
12249  {
12250  static inline void process(Iterator itr, T& t)
12251  {
12253  t += static_cast<T>((itr[0] - '0') * 10000000000000000LL);
12254  }
12255  };
12256 
12257  template <typename T, typename Iterator>
12258  struct numeric_convert_impl<T,Iterator,16>
12259  {
12260  static inline void process(Iterator itr, T& t)
12261  {
12262  T x = static_cast<T>((itr[ 0] - '0') * 1000000000000000LL);
12263  x += static_cast<T>((itr[ 1] - '0') * 100000000000000LL);
12264  x += static_cast<T>((itr[ 2] - '0') * 10000000000000LL);
12265  x += static_cast<T>((itr[ 3] - '0') * 1000000000000LL);
12266  x += static_cast<T>((itr[ 4] - '0') * 100000000000LL);
12267  x += static_cast<T>((itr[ 5] - '0') * 10000000000LL);
12268  x += static_cast<T>((itr[ 6] - '0') * 1000000000LL);
12269  x += static_cast<T>((itr[ 7] - '0') * 100000000LL);
12270  x += static_cast<T>((itr[ 8] - '0') * 10000000LL);
12271  x += static_cast<T>((itr[ 9] - '0') * 1000000LL);
12272  x += static_cast<T>((itr[10] - '0') * 100000LL);
12273  x += static_cast<T>((itr[11] - '0') * 10000LL);
12274  x += static_cast<T>((itr[12] - '0') * 1000LL);
12275  x += static_cast<T>((itr[13] - '0') * 100LL);
12276  x += static_cast<T>((itr[14] - '0') * 10LL);
12277  x += static_cast<T>((itr[15] - '0') );
12278  t = x;
12279  }
12280  };
12281 
12282  template <typename T, typename Iterator>
12283  struct numeric_convert_impl<T,Iterator,15>
12284  {
12285  static inline void process(Iterator itr, T& t)
12286  {
12287  T x = static_cast<T>((itr[ 0] - '0') * 100000000000000LL);
12288  x += static_cast<T>((itr[ 1] - '0') * 10000000000000LL);
12289  x += static_cast<T>((itr[ 2] - '0') * 1000000000000LL);
12290  x += static_cast<T>((itr[ 3] - '0') * 100000000000LL);
12291  x += static_cast<T>((itr[ 4] - '0') * 10000000000LL);
12292  x += static_cast<T>((itr[ 5] - '0') * 1000000000LL);
12293  x += static_cast<T>((itr[ 6] - '0') * 100000000LL);
12294  x += static_cast<T>((itr[ 7] - '0') * 10000000LL);
12295  x += static_cast<T>((itr[ 8] - '0') * 1000000LL);
12296  x += static_cast<T>((itr[ 9] - '0') * 100000LL);
12297  x += static_cast<T>((itr[10] - '0') * 10000LL);
12298  x += static_cast<T>((itr[11] - '0') * 1000LL);
12299  x += static_cast<T>((itr[12] - '0') * 100LL);
12300  x += static_cast<T>((itr[13] - '0') * 10LL);
12301  x += static_cast<T>((itr[14] - '0') );
12302  t = x;
12303  }
12304  };
12305 
12306  template <typename T, typename Iterator>
12307  struct numeric_convert_impl<T,Iterator,14>
12308  {
12309  static inline void process(Iterator itr, T& t)
12310  {
12311  T x = static_cast<T>((itr[ 0] - '0') * 10000000000000LL);
12312  x += static_cast<T>((itr[ 1] - '0') * 1000000000000LL);
12313  x += static_cast<T>((itr[ 2] - '0') * 100000000000LL);
12314  x += static_cast<T>((itr[ 3] - '0') * 10000000000LL);
12315  x += static_cast<T>((itr[ 4] - '0') * 1000000000LL);
12316  x += static_cast<T>((itr[ 5] - '0') * 100000000LL);
12317  x += static_cast<T>((itr[ 6] - '0') * 10000000LL);
12318  x += static_cast<T>((itr[ 7] - '0') * 1000000LL);
12319  x += static_cast<T>((itr[ 8] - '0') * 100000LL);
12320  x += static_cast<T>((itr[ 9] - '0') * 10000LL);
12321  x += static_cast<T>((itr[10] - '0') * 1000LL);
12322  x += static_cast<T>((itr[11] - '0') * 100LL);
12323  x += static_cast<T>((itr[12] - '0') * 10LL);
12324  x += static_cast<T>((itr[13] - '0') );
12325  t = x;
12326  }
12327  };
12328 
12329  template <typename T, typename Iterator>
12330  struct numeric_convert_impl<T,Iterator,13>
12331  {
12332  static inline void process(Iterator itr, T& t)
12333  {
12334  T x = static_cast<T>((itr[ 0] - '0') * 1000000000000LL);
12335  x += static_cast<T>((itr[ 1] - '0') * 100000000000LL);
12336  x += static_cast<T>((itr[ 2] - '0') * 10000000000LL);
12337  x += static_cast<T>((itr[ 3] - '0') * 1000000000LL);
12338  x += static_cast<T>((itr[ 4] - '0') * 100000000LL);
12339  x += static_cast<T>((itr[ 5] - '0') * 10000000LL);
12340  x += static_cast<T>((itr[ 6] - '0') * 1000000LL);
12341  x += static_cast<T>((itr[ 7] - '0') * 100000LL);
12342  x += static_cast<T>((itr[ 8] - '0') * 10000LL);
12343  x += static_cast<T>((itr[ 9] - '0') * 1000LL);
12344  x += static_cast<T>((itr[10] - '0') * 100LL);
12345  x += static_cast<T>((itr[11] - '0') * 10LL);
12346  x += static_cast<T>((itr[12] - '0') );
12347  t = x;
12348  }
12349  };
12350 
12351  template <typename T, typename Iterator>
12352  struct numeric_convert_impl<T,Iterator,12>
12353  {
12354  static inline void process(Iterator itr, T& t)
12355  {
12356  T x = static_cast<T>((itr[ 0] - '0') * 100000000000LL);
12357  x += static_cast<T>((itr[ 1] - '0') * 10000000000LL);
12358  x += static_cast<T>((itr[ 2] - '0') * 1000000000LL);
12359  x += static_cast<T>((itr[ 3] - '0') * 100000000LL);
12360  x += static_cast<T>((itr[ 4] - '0') * 10000000LL);
12361  x += static_cast<T>((itr[ 5] - '0') * 1000000LL);
12362  x += static_cast<T>((itr[ 6] - '0') * 100000LL);
12363  x += static_cast<T>((itr[ 7] - '0') * 10000LL);
12364  x += static_cast<T>((itr[ 8] - '0') * 1000LL);
12365  x += static_cast<T>((itr[ 9] - '0') * 100LL);
12366  x += static_cast<T>((itr[10] - '0') * 10LL);
12367  x += static_cast<T>((itr[11] - '0') );
12368  t = x;
12369  }
12370  };
12371 
12372  template <typename T, typename Iterator>
12373  struct numeric_convert_impl<T,Iterator,11>
12374  {
12375  static inline void process(Iterator itr, T& t)
12376  {
12377  T x = static_cast<T>((itr[ 0] - '0') * 10000000000LL);
12378  x += static_cast<T>((itr[ 1] - '0') * 1000000000LL);
12379  x += static_cast<T>((itr[ 2] - '0') * 100000000LL);
12380  x += static_cast<T>((itr[ 3] - '0') * 10000000LL);
12381  x += static_cast<T>((itr[ 4] - '0') * 1000000LL);
12382  x += static_cast<T>((itr[ 5] - '0') * 100000LL);
12383  x += static_cast<T>((itr[ 6] - '0') * 10000LL);
12384  x += static_cast<T>((itr[ 7] - '0') * 1000LL);
12385  x += static_cast<T>((itr[ 8] - '0') * 100LL);
12386  x += static_cast<T>((itr[ 9] - '0') * 10LL);
12387  x += static_cast<T>((itr[10] - '0') );
12388  t = x;
12389  }
12390  };
12391 
12392  template <typename T, typename Iterator>
12393  struct numeric_convert_impl<T,Iterator,10>
12394  {
12395  static inline void process(Iterator itr, T& t)
12396  {
12397  T x = static_cast<T>((itr[0] - '0') * 1000000000);
12398  x += static_cast<T>((itr[1] - '0') * 100000000);
12399  x += static_cast<T>((itr[2] - '0') * 10000000);
12400  x += static_cast<T>((itr[3] - '0') * 1000000);
12401  x += static_cast<T>((itr[4] - '0') * 100000);
12402  x += static_cast<T>((itr[5] - '0') * 10000);
12403  x += static_cast<T>((itr[6] - '0') * 1000);
12404  x += static_cast<T>((itr[7] - '0') * 100);
12405  x += static_cast<T>((itr[8] - '0') * 10);
12406  x += static_cast<T>((itr[9] - '0') );
12407  t = x;
12408  }
12409  };
12410 
12411  template <typename T, typename Iterator>
12412  struct numeric_convert_impl<T,Iterator,9>
12413  {
12414  static inline void process(Iterator itr, T& t)
12415  {
12416  T x = static_cast<T>((itr[0] - '0') * 100000000);
12417  x += static_cast<T>((itr[1] - '0') * 10000000);
12418  x += static_cast<T>((itr[2] - '0') * 1000000);
12419  x += static_cast<T>((itr[3] - '0') * 100000);
12420  x += static_cast<T>((itr[4] - '0') * 10000);
12421  x += static_cast<T>((itr[5] - '0') * 1000);
12422  x += static_cast<T>((itr[6] - '0') * 100);
12423  x += static_cast<T>((itr[7] - '0') * 10);
12424  x += static_cast<T>((itr[8] - '0') );
12425  t = x;
12426  }
12427  };
12428 
12429  template <typename T, typename Iterator>
12430  struct numeric_convert_impl<T,Iterator,8>
12431  {
12432  static inline void process(Iterator itr, T& t)
12433  {
12434  T x = static_cast<T>((itr[0] - '0') * 10000000);
12435  x += static_cast<T>((itr[1] - '0') * 1000000);
12436  x += static_cast<T>((itr[2] - '0') * 100000);
12437  x += static_cast<T>((itr[3] - '0') * 10000);
12438  x += static_cast<T>((itr[4] - '0') * 1000);
12439  x += static_cast<T>((itr[5] - '0') * 100);
12440  x += static_cast<T>((itr[6] - '0') * 10);
12441  x += static_cast<T>((itr[7] - '0') );
12442  t = x;
12443  }
12444  };
12445 
12446  template <typename T, typename Iterator>
12447  struct numeric_convert_impl<T,Iterator,7>
12448  {
12449  static inline void process(Iterator itr, T& t)
12450  {
12451  T x = static_cast<T>((itr[0] - '0') * 1000000);
12452  x += static_cast<T>((itr[1] - '0') * 100000);
12453  x += static_cast<T>((itr[2] - '0') * 10000);
12454  x += static_cast<T>((itr[3] - '0') * 1000);
12455  x += static_cast<T>((itr[4] - '0') * 100);
12456  x += static_cast<T>((itr[5] - '0') * 10);
12457  x += static_cast<T>((itr[6] - '0') );
12458  t = x;
12459  }
12460  };
12461 
12462  template <typename T, typename Iterator>
12463  struct numeric_convert_impl<T,Iterator,6>
12464  {
12465  static inline void process(Iterator itr, T& t)
12466  {
12467  T x = static_cast<T>((itr[0] - '0') * 100000);
12468  x += static_cast<T>((itr[1] - '0') * 10000);
12469  x += static_cast<T>((itr[2] - '0') * 1000);
12470  x += static_cast<T>((itr[3] - '0') * 100);
12471  x += static_cast<T>((itr[4] - '0') * 10);
12472  x += static_cast<T>((itr[5] - '0') );
12473  t = x;
12474  }
12475  };
12476 
12477  template <typename T, typename Iterator>
12478  struct numeric_convert_impl<T,Iterator,5>
12479  {
12480  static inline void process(Iterator itr, T& t)
12481  {
12482  T x = static_cast<T>((itr[0] - '0') * 10000);
12483  x += static_cast<T>((itr[1] - '0') * 1000);
12484  x += static_cast<T>((itr[2] - '0') * 100);
12485  x += static_cast<T>((itr[3] - '0') * 10);
12486  x += static_cast<T>((itr[4] - '0') );
12487  t = x;
12488  }
12489  };
12490 
12491  template <typename T, typename Iterator>
12492  struct numeric_convert_impl<T,Iterator,4>
12493  {
12494  static inline void process(Iterator itr, T& t)
12495  {
12496  T x = static_cast<T>((itr[0] - '0') * 1000);
12497  x += static_cast<T>((itr[1] - '0') * 100);
12498  x += static_cast<T>((itr[2] - '0') * 10);
12499  x += static_cast<T>((itr[3] - '0') );
12500  t = x;
12501  }
12502  };
12503 
12504  template <typename T, typename Iterator>
12505  struct numeric_convert_impl<T,Iterator,3>
12506  {
12507  static inline void process(Iterator itr, T& t)
12508  {
12509  T x = static_cast<T>((itr[0] - '0') * 100);
12510  x += static_cast<T>((itr[1] - '0') * 10);
12511  x += static_cast<T>((itr[2] - '0') );
12512  t = x;
12513  }
12514  };
12515 
12516  template <typename T, typename Iterator>
12517  struct numeric_convert_impl<T,Iterator,2>
12518  {
12519  static inline void process(Iterator itr, T& t)
12520  {
12521  T x = static_cast<T>((itr[0] - '0') * 10);
12522  x += static_cast<T>((itr[1] - '0') );
12523  t = x;
12524  }
12525  };
12526 
12527  template <typename T, typename Iterator>
12528  struct numeric_convert_impl<T,Iterator,1>
12529  {
12530  static inline void process(Iterator itr, T& t)
12531  {
12532  t = static_cast<T>((itr[0] - '0'));
12533  }
12534  };
12535 
12536  template <typename T, typename Iterator>
12537  struct numeric_convert_impl<T,Iterator,0>
12538  {
12539  static inline void process(Iterator, T& t)
12540  {
12541  t = 0;
12542  }
12543  };
12544 
12545  template <typename T, typename NoneSignedTag>
12546  inline bool negate(T&, NoneSignedTag)
12547  {
12548  return false;
12549  }
12550 
12551  template <typename T>
12553  {
12554  t = -t;
12555  return true;
12556  }
12557 
12558  } // namespace details
12559 
12560  template <int N, typename Iterator>
12561  inline bool all_digits_check(Iterator itr)
12562  {
12563  typedef typename strtk::details::is_valid_iterator<Iterator>::type itr_type;
12565  }
12566 
12567  template <int N, typename Iterator>
12568  inline bool all_digits_check(const std::string& s)
12569  {
12570  return all_digits_check<N,const char*>(s.data());
12571  }
12572 
12573  template <typename Iterator>
12574  inline bool all_digits_check(const std::size_t& n, Iterator itr)
12575  {
12576  switch (n)
12577  {
12598  default : return false;
12599  }
12600  }
12601 
12602  template <typename Iterator>
12603  inline bool all_digits_check(Iterator begin, Iterator end)
12604  {
12605  return all_digits_check(std::distance(begin,end),begin);
12606  }
12607 
12608  inline bool all_digits_check(const std::string& s)
12609  {
12610  return all_digits_check(s.size(),s.data());
12611  }
12612 
12613  template <int N, typename Iterator>
12614  inline bool signed_all_digits_check(Iterator itr)
12615  {
12616  if (('-' == (*itr)) || ('+' == (*itr)))
12617  return all_digits_check<Iterator,N - 1>((itr + 1));
12618  else
12619  return all_digits_check<Iterator,N>(itr);
12620  }
12621 
12622  template <typename Iterator>
12623  inline bool signed_all_digits_check(const std::size_t& n, Iterator itr)
12624  {
12625  if (('-' == (*itr)) || ('+' == (*itr)))
12626  return all_digits_check(n - 1,(itr + 1));
12627  else
12628  return all_digits_check(n,itr);
12629  }
12630 
12631  template <int N>
12632  inline bool signed_all_digits_check(const std::string& s)
12633  {
12634  return signed_all_digits_check<N,const char*>(s.data());
12635  }
12636 
12637  template <typename Iterator>
12638  inline bool signed_all_digits_check(Iterator begin, Iterator end)
12639  {
12640  return signed_all_digits_check(std::distance(begin,end),begin);
12641  }
12642 
12643  inline bool signed_all_digits_check(const std::string& s)
12644  {
12645  return signed_all_digits_check(s.size(),s.data());
12646  }
12647 
12648  template <int N, typename T, typename Iterator>
12649  inline void numeric_convert(Iterator itr, T& t, const bool digit_check = false)
12650  {
12651  typedef typename strtk::details::is_valid_iterator<Iterator>::type itr_type;
12652  if (digit_check)
12653  {
12654  if (!all_digits_check<N,Iterator>(itr))
12655  {
12656  t = 0;
12657  return;
12658  }
12659  }
12660 
12662  }
12663 
12664  template <int N, typename T>
12665  inline void numeric_convert(const std::string& s, T& t, const bool digit_check = false)
12666  {
12667  numeric_convert<N,T,const char*>(s.data(),t,digit_check);
12668  }
12669 
12670  template <typename T, typename Iterator>
12671  inline bool numeric_convert(const std::size_t& n,
12672  Iterator itr, T& t,
12673  const bool digit_check = false)
12674  {
12675  if (digit_check)
12676  {
12677  if (!all_digits_check(n,itr))
12678  {
12679  return false;
12680  }
12681  }
12682 
12683  switch (n)
12684  {
12685  case 0 : details::numeric_convert_impl<T,Iterator, 0>::process(itr,t); return true;
12686  case 1 : details::numeric_convert_impl<T,Iterator, 1>::process(itr,t); return true;
12687  case 2 : details::numeric_convert_impl<T,Iterator, 2>::process(itr,t); return true;
12688  case 3 : details::numeric_convert_impl<T,Iterator, 3>::process(itr,t); return true;
12689  case 4 : details::numeric_convert_impl<T,Iterator, 4>::process(itr,t); return true;
12690  case 5 : details::numeric_convert_impl<T,Iterator, 5>::process(itr,t); return true;
12691  case 6 : details::numeric_convert_impl<T,Iterator, 6>::process(itr,t); return true;
12692  case 7 : details::numeric_convert_impl<T,Iterator, 7>::process(itr,t); return true;
12693  case 8 : details::numeric_convert_impl<T,Iterator, 8>::process(itr,t); return true;
12694  case 9 : details::numeric_convert_impl<T,Iterator, 9>::process(itr,t); return true;
12695  case 10 : details::numeric_convert_impl<T,Iterator,10>::process(itr,t); return true;
12696  case 11 : details::numeric_convert_impl<T,Iterator,11>::process(itr,t); return true;
12697  case 12 : details::numeric_convert_impl<T,Iterator,12>::process(itr,t); return true;
12698  case 13 : details::numeric_convert_impl<T,Iterator,13>::process(itr,t); return true;
12699  case 14 : details::numeric_convert_impl<T,Iterator,14>::process(itr,t); return true;
12700  case 15 : details::numeric_convert_impl<T,Iterator,15>::process(itr,t); return true;
12701  case 16 : details::numeric_convert_impl<T,Iterator,16>::process(itr,t); return true;
12702  case 17 : details::numeric_convert_impl<T,Iterator,17>::process(itr,t); return true;
12703  case 18 : details::numeric_convert_impl<T,Iterator,18>::process(itr,t); return true;
12704  case 19 : details::numeric_convert_impl<T,Iterator,19>::process(itr,t); return true;
12705  default : return false;
12706  }
12707  }
12708 
12709  template <typename T>
12710  inline void numeric_convert(const std::string& s, T& t, const bool digit_check = false)
12711  {
12712  numeric_convert(s.size(),s.data(),t,digit_check);
12713  }
12714 
12715  template <int N, typename T, typename Iterator>
12716  inline void signed_numeric_convert(Iterator itr, T& t, const bool digit_check = false)
12717  {
12718  if ('-' == (*itr))
12719  {
12720  numeric_convert<N - 1,T,Iterator>((itr + 1),t,digit_check);
12722  details::negate(t,type);
12723  }
12724  else if ('+' == (*itr))
12725  {
12726  numeric_convert<N - 1,T,Iterator>((itr + 1),t,digit_check);
12727  }
12728  else
12729  numeric_convert<N,T,Iterator>(itr,t,digit_check);
12730  }
12731 
12732  template <typename T, typename Iterator>
12733  inline bool signed_numeric_convert(const std::size_t& n,
12734  Iterator itr,
12735  T& t,
12736  const bool digit_check = false)
12737  {
12738  if ('-' == (*itr))
12739  {
12740  bool result = numeric_convert((n - 1),(itr + 1),t,digit_check);
12742  return details::negate<T>(t,type) && result;
12743  }
12744  else if ('+' == (*itr))
12745  {
12746  return numeric_convert((n - 1),(itr + 1),t,digit_check);
12747  }
12748  else
12749  return numeric_convert(n,itr,t,digit_check);
12750  }
12751 
12752  template <int N, typename T>
12753  inline void signed_numeric_convert(const std::string& s,
12754  T& t,
12755  const bool digit_check = false)
12756  {
12757  signed_numeric_convert<N,T,const char*>(s.data(),t,digit_check);
12758  }
12759 
12760  template <typename T>
12761  inline bool signed_numeric_convert(const std::string& s,
12762  T& t,
12763  const bool digit_check = false)
12764  {
12765  return signed_numeric_convert<T,const char*>(s.size(),s.data(),t,digit_check);
12766  }
12767 
12768  } // namespace fast
12769 
12770  namespace binary
12771  {
12772 
12773  namespace details
12774  {
12775  namespace details_endian
12776  {
12777  #if (defined(__LITTLE_ENDIAN__)) ||\
12778  (defined(WIN32)) ||\
12779  (defined(__MINGW32_VERSION)) ||\
12780  (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__))
12781  static const bool __le_result = true;
12782  static const bool __be_result = false;
12783  #else
12784  static const bool __le_result = false;
12785  static const bool __be_result = true;
12786  #endif
12787  }
12788 
12789  static inline bool is_little_endian()
12790  {
12791  //Is the current architecture/platform little-endian?
12792  return details_endian::__le_result;
12793  }
12794 
12795  static inline bool is_big_endian()
12796  {
12797  return details_endian::__be_result;
12798  }
12799 
12800  static inline unsigned short convert(const unsigned short v)
12801  {
12802  //static_assert(2 == sizeof(v),"");
12803  return ((v >> 8) & 0x00FF) | ((v << 8) & 0xFFFF);
12804  }
12805 
12806  static inline unsigned int convert(const unsigned int v)
12807  {
12808  //static_assert(4 == sizeof(v),"");
12809  return ((v >> 24) & 0x000000FF) | ((v << 24) & 0x0000FF00) |
12810  ((v << 8) & 0x00FF0000) | ((v >> 8) & 0xFF000000);
12811  }
12812 
12813  static inline unsigned long long int convert(const unsigned long long int v)
12814  {
12815  //static_assert(8 == sizeof(v),"");
12816  return ((v >> 56) & 0x00000000000000FFLL) | ((v << 56) & 0xFF00000000000000LL) |
12817  ((v >> 40) & 0x000000000000FF00LL) | ((v << 40) & 0x00FF000000000000LL) |
12818  ((v >> 24) & 0x0000000000FF0000LL) | ((v << 24) & 0x0000FF0000000000LL) |
12819  ((v >> 8) & 0x00000000FF000000LL) | ((v << 8) & 0x000000FF00000000LL) ;
12820  }
12821 
12822  static inline short convert(const short v)
12823  {
12824  return static_cast<short>(convert(static_cast<unsigned short>(v)));
12825  }
12826 
12827  static inline int convert(const int v)
12828  {
12829  return static_cast<int>(convert(static_cast<unsigned int>(v)));
12830  }
12831 
12832  static inline unsigned long long int convert(const long long int v)
12833  {
12834  return static_cast<long long>(convert(static_cast<unsigned long long int>(v)));
12835  }
12836 
12837  static inline unsigned short convert_to_be(const unsigned short v)
12838  {
12839  if (is_little_endian()) convert(v);
12840  return v;
12841  }
12842 
12843  static inline unsigned int convert_to_be(const unsigned int v)
12844  {
12845  if (is_little_endian()) convert(v);
12846  return v;
12847  }
12848 
12849  static inline unsigned long long int convert_to_be(const unsigned long long int v)
12850  {
12851  if (is_little_endian()) convert(v);
12852  return v;
12853  }
12854 
12855  static inline short convert_to_be(const short v)
12856  {
12857  if (is_little_endian()) convert(v);
12858  return v;
12859  }
12860 
12861  static inline int convert_to_be(const int v)
12862  {
12863  if (is_little_endian()) convert(v);
12864  return v;
12865  }
12866 
12867  static inline unsigned long long int convert_to_be(const long long int v)
12868  {
12869  if (is_little_endian()) convert(v);
12870  return v;
12871  }
12872 
12873  static inline unsigned short convert_to_le(const unsigned short v)
12874  {
12875  if (is_big_endian()) convert(v);
12876  return v;
12877  }
12878 
12879  static inline unsigned int convert_to_le(const unsigned int v)
12880  {
12881  if (is_big_endian()) convert(v);
12882  return v;
12883  }
12884 
12885  static inline unsigned long long int convert_to_le(const unsigned long long int v)
12886  {
12887  if (is_big_endian()) convert(v);
12888  return v;
12889  }
12890 
12891  static inline short convert_to_le(const short v)
12892  {
12893  if (is_big_endian()) convert(v);
12894  return v;
12895  }
12896 
12897  static inline int convert_to_le(const int v)
12898  {
12899  if (is_big_endian()) convert(v);
12900  return v;
12901  }
12902 
12903  static inline unsigned long long int convert_to_le(const long long int v)
12904  {
12905  if (is_big_endian()) convert(v);
12906  return v;
12907  }
12908 
12909  class marker
12910  {
12911  private:
12912 
12913  typedef std::pair<std::size_t,char*> mark_type;
12914 
12915  public:
12916 
12917  inline bool reset(std::size_t& v1, char*& v2)
12918  {
12919  if (stack_.empty())
12920  return false;
12921  v1 = stack_.top().first;
12922  v2 = stack_.top().second;
12923  stack_.pop();
12924  return true;
12925  }
12926 
12927  inline void mark(const std::size_t& v1,char* v2)
12928  {
12929  stack_.push(std::make_pair(v1,v2));
12930  }
12931 
12932  private:
12933 
12934  std::stack<mark_type> stack_;
12935  };
12936 
12937  }
12938 
12939  class reader
12940  {
12941  public:
12942 
12943  // should be sourced from cstdint
12944  typedef unsigned int uint32_t;
12945  typedef unsigned short uint16_t;
12946  typedef unsigned char uint8_t;
12947  typedef unsigned long long int uint64_t;
12948 
12949  template <typename T>
12950  reader(T* buffer,
12951  const std::size_t& buffer_length)
12952  : original_buffer_(reinterpret_cast<char*>(buffer)),
12953  buffer_(reinterpret_cast<char*>(buffer)),
12954  buffer_length_(buffer_length * sizeof(T)),
12955  amount_read_sofar_(0)
12956  {}
12957 
12958  inline bool operator!() const
12959  {
12960  return (0 == buffer_length_) ||
12961  (0 == original_buffer_) ||
12962  (0 == buffer_);
12963  }
12964 
12965  inline void reset(const bool clear_buffer = false)
12966  {
12967  amount_read_sofar_ = 0;
12968  buffer_ = original_buffer_;
12969  if (clear_buffer)
12970  clear();
12971  }
12972 
12973  inline std::size_t position() const
12974  {
12975  return amount_read_sofar_;
12976  }
12977 
12978  inline const char* position_ptr() const
12979  {
12980  return buffer_ ;
12981  }
12982 
12983  inline std::size_t amount_read()
12984  {
12985  return amount_read_sofar_;
12986  }
12987 
12988  inline bool rewind(const std::size_t& n_bytes)
12989  {
12990  if (n_bytes <= amount_read_sofar_)
12991  {
12992  amount_read_sofar_ -= n_bytes;
12993  buffer_ -= n_bytes;
12994  return true;
12995  }
12996  else
12997  return false;
12998  }
12999 
13000  inline bool seek(const int& n_bytes)
13001  {
13002  if (n_bytes < 0)
13003  return rewind(-n_bytes);
13004  else if (n_bytes > 0)
13005  {
13006  if ((amount_read_sofar_ + n_bytes) <= buffer_length_)
13007  {
13008  amount_read_sofar_ += n_bytes;
13009  buffer_ += n_bytes;
13010  return true;
13011  }
13012  else
13013  return false;
13014  }
13015  else
13016  return true;
13017  }
13018 
13019  inline void clear()
13020  {
13021  reset();
13022  std::memset(buffer_,0x00,buffer_length_);
13023  }
13024 
13025  template <typename T>
13026  inline bool operator()(T*& data, uint32_t& length, const bool read_length = true)
13027  {
13028  if (read_length && !operator()(length))
13029  return false;
13030 
13031  const std::size_t raw_size = length * sizeof(T);
13032  if (!buffer_capacity_ok(raw_size))
13033  return false;
13034 
13035  if (read_length)
13036  {
13037  data = new T[length];
13038  }
13039  std::copy(buffer_, buffer_ + raw_size, reinterpret_cast<char*>(data));
13040  buffer_ += raw_size;
13041  amount_read_sofar_ += raw_size;
13042  return true;
13043  }
13044 
13045  template <typename T>
13046  inline bool operator()(T*& data, uint64_t& length, const bool read_length = true)
13047  {
13048  uint32_t l = 0;
13049  if (read_length)
13050  l = static_cast<uint32_t>(length);
13051  if (!operator()(data,l,read_length))
13052  return false;
13053  if (read_length)
13054  length = l;
13055  return true;
13056  }
13057 
13058  inline bool operator()(std::string& output)
13059  {
13060  uint32_t length = 0;
13061  if (!operator()(length))
13062  return false;
13063 
13064  if (!buffer_capacity_ok(length))
13065  return false;
13066 
13067  output.resize(length);
13068  std::copy(buffer_,
13069  buffer_ + length,
13070  const_cast<char*>(output.data()));
13071  buffer_ += length;
13072  amount_read_sofar_ += length;
13073  return true;
13074  }
13075 
13076  template <typename T1, typename T2>
13077  inline bool operator()(std::pair<T1,T2>& p)
13078  {
13079  if (!operator()(p.first))
13080  return false;
13081  if (!operator()(p.second))
13082  return false;
13083  return true;
13084  }
13085 
13086  template <typename T,
13087  typename Allocator,
13088  template <typename,typename> class Sequence>
13089  inline bool operator()(Sequence<T,Allocator>& seq)
13090  {
13091  uint32_t size = 0;
13092  if (!read_pod(size))
13093  return false;
13094 
13095  const std::size_t raw_size = size * sizeof(T);
13096  if (!buffer_capacity_ok(raw_size))
13097  return false;
13098 
13099  T t = T();
13100 
13101  for (std::size_t i = 0; i < size; ++i)
13102  {
13103  if (operator()(t))
13104  seq.push_back(t);
13105  else
13106  return false;
13107  }
13108  return true;
13109  }
13110 
13111  template <typename T, typename Allocator>
13112  inline bool operator()(std::vector<T,Allocator>& vec)
13113  {
13114  uint32_t size = 0;
13115  if (!read_pod(size))
13116  return false;
13117  const std::size_t raw_size = size * sizeof(T);
13118  if (!buffer_capacity_ok(raw_size))
13119  return false;
13120  vec.resize(size);
13121  return selector<T>::type::batch_vector_read(*this,size,vec,false);
13122  }
13123 
13124  template <typename T,
13125  typename Comparator,
13126  typename Allocator>
13127  inline bool operator()(std::set<T,Comparator,Allocator>& set)
13128  {
13129  uint32_t size = 0;
13130  if (!read_pod(size))
13131  return false;
13132 
13133  const std::size_t raw_size = size * sizeof(T);
13134  if (!buffer_capacity_ok(raw_size))
13135  return false;
13136 
13137  T t;
13138  for (std::size_t i = 0; i < size; ++i)
13139  {
13140  if (!operator()(t))
13141  return false;
13142  set.insert(t);
13143  }
13144 
13145  return true;
13146  }
13147 
13148  template <typename T,
13149  typename Allocator,
13150  typename Comparator>
13151  inline bool operator()(std::multiset<T,Allocator,Comparator>& multiset)
13152  {
13153  uint32_t size = 0;
13154  if (!read_pod(size))
13155  return false;
13156 
13157  const std::size_t raw_size = size * sizeof(T);
13158  if (!buffer_capacity_ok(raw_size))
13159  return false;
13160 
13161  T t;
13162  for (std::size_t i = 0; i < size; ++i)
13163  {
13164  if (!operator()(t))
13165  return false;
13166  multiset.insert(t);
13167  }
13168 
13169  return true;
13170  }
13171 
13172  inline bool operator()(std::ifstream& stream, const std::size_t& length)
13173  {
13174  if (length > buffer_length_) return false;
13175  stream.read(original_buffer_,static_cast<std::streamsize>(length));
13176  return true;
13177  }
13178 
13179  inline bool operator()(std::ifstream& stream)
13180  {
13181  if (0 == amount_read_sofar_) return false;
13182  stream.read(original_buffer_,static_cast<std::streamsize>(amount_read_sofar_));
13183  return true;
13184  }
13185 
13186  template <typename T>
13187  inline bool operator()(T& output)
13188  {
13189  return selector<T>::type::run(*this,output);
13190  }
13191 
13192  template <typename T>
13193  inline bool operator()(const T& output)
13194  {
13195  return selector<T>::type::run(*this,const_cast<T&>(output));
13196  }
13197 
13198  template <typename T>
13199  inline bool be_to_native(T& output)
13200  {
13201  //From big-endian to native
13202  if (details::is_little_endian())
13203  {
13204  if (!operator()<T>(output)) return false;
13205  output = details::convert(output);
13206  return true;
13207  }
13208  else
13209  return operator()(output);
13210  }
13211 
13212  template <typename T>
13213  inline bool le_to_native(T& output)
13214  {
13215  //From little-endian to native
13216  if (details::is_little_endian())
13217  return operator()(output);
13218  else
13219  {
13220  if (!operator()<T>(output)) return false;
13221  output = details::convert(output);
13222  return true;
13223  }
13224  }
13225 
13226  template <typename T, std::size_t N>
13227  inline bool operator()(T (&output)[N])
13228  {
13229  const std::size_t raw_size = N * sizeof(T);
13230  if (buffer_capacity_ok(raw_size))
13231  {
13232  std::copy(buffer_,
13233  buffer_ + raw_size,
13234  reinterpret_cast<char*>(output));
13235  buffer_ += raw_size;
13236  amount_read_sofar_ += raw_size;
13237  return true;
13238  }
13239  else
13240  return false;
13241  }
13242 
13243  template <typename T>
13244  inline bool operator()(T& output, const std::size_t& size)
13245  {
13246  if (buffer_capacity_ok(size))
13247  {
13248  bool result = strtk::string_to_type_converter<char*,T>(buffer_,buffer_ + size,output);
13249  buffer_ += size;
13250  amount_read_sofar_ += size;
13251  return result;
13252  }
13253  else
13254  return false;
13255  }
13256 
13257  inline void mark()
13258  {
13259  marker_.mark(amount_read_sofar_,buffer_);
13260  }
13261 
13262  inline bool reset_to_mark()
13263  {
13264  return marker_.reset(amount_read_sofar_,buffer_);
13265  }
13266 
13267  private:
13268 
13269  reader();
13270  reader(const reader& s);
13271  reader& operator=(const reader& s);
13272 
13273  inline bool buffer_capacity_ok(const std::size_t& required_read_qty)
13274  {
13275  return ((required_read_qty + amount_read_sofar_) <= buffer_length_);
13276  }
13277 
13278  template <typename Type>
13279  struct selector
13280  {
13281  private:
13282 
13283  template <typename T, typename IsPOD>
13284  struct selector_impl
13285  {
13286  template <typename Reader>
13287  static inline bool run(Reader& r, T& t)
13288  {
13289  return t(r);
13290  }
13291 
13292  template <typename Reader,
13293  typename Allocator>
13294  static inline bool batch_vector_read(Reader& r,
13295  const std::size_t& size,
13296  std::vector<T,Allocator>& v,
13297  const bool)
13298  {
13299  T t;
13300  for (std::size_t i = 0; i < size; ++i)
13301  {
13302  if (r.operator()(t))
13303  v[i] = t;
13304  else
13305  return false;
13306  }
13307  return true;
13308  }
13309  };
13310 
13311  template <typename T>
13312  struct selector_impl<T,strtk::details::yes_t>
13313  {
13314  template <typename Reader>
13315  static inline bool run(Reader& r,
13316  T& t,
13317  const bool perform_buffer_capacity_check = true)
13318  {
13319  return r.read_pod(t,perform_buffer_capacity_check);
13320  }
13321 
13322  template <typename Reader,
13323  typename Allocator>
13324  static inline bool batch_vector_read(Reader& r,
13325  const std::size_t& size,
13326  std::vector<T,Allocator>& v,
13327  const bool)
13328  {
13329  const std::size_t raw_size = sizeof(T) * size;
13330  char* ptr = const_cast<char*>(reinterpret_cast<const char*>(&v[0]));
13331  std::copy(r.buffer_, r.buffer_ + raw_size, ptr);
13332  r.buffer_ += raw_size;
13333  r.amount_read_sofar_ += raw_size;
13334  return true;
13335  }
13336  };
13337 
13338  public:
13339 
13340  typedef selector_impl<Type,typename strtk::details::is_pod<Type>::result_t> type;
13341  };
13342 
13343  template <typename T>
13344  inline bool read_pod(T& data, const bool perform_buffer_capacity_check = true)
13345  {
13346  static const std::size_t data_length = sizeof(T);
13347  if (perform_buffer_capacity_check)
13348  {
13349  if (!buffer_capacity_ok(data_length))
13350  return false;
13351  }
13352  data = (*reinterpret_cast<T*>(buffer_));
13353  buffer_ += data_length;
13354  amount_read_sofar_ += data_length;
13355  return true;
13356  }
13357 
13358  char* const original_buffer_;
13359  char* buffer_;
13360  std::size_t buffer_length_;
13361  std::size_t amount_read_sofar_;
13362  details::marker marker_;
13363  };
13364 
13365  class writer
13366  {
13367  public:
13368 
13369  // should be sourced from cstdint
13370  // should be sourced from cstdint
13371  typedef unsigned int uint32_t;
13372  typedef unsigned short uint16_t;
13373  typedef unsigned char uint8_t;
13374  typedef unsigned long long int uint64_t;
13375 
13376  template <typename T>
13377  writer(T* buffer, const std::size_t& buffer_length)
13378  : original_buffer_(reinterpret_cast<char*>(buffer)),
13379  buffer_(reinterpret_cast<char*>(buffer)),
13380  buffer_length_(buffer_length * sizeof(T)),
13381  amount_written_sofar_(0)
13382  {}
13383 
13384  inline bool operator!() const
13385  {
13386  return (0 == buffer_length_) ||
13387  (0 == original_buffer_) ||
13388  (0 == buffer_);
13389  }
13390 
13391  inline void reset(const bool clear_buffer = false)
13392  {
13393  amount_written_sofar_ = 0;
13394  buffer_ = original_buffer_;
13395  if (clear_buffer)
13396  clear();
13397  }
13398 
13399  inline std::size_t position() const
13400  {
13401  return amount_written_sofar_;
13402  }
13403 
13404  inline const char* position_ptr() const
13405  {
13406  return buffer_ ;
13407  }
13408 
13409  inline std::size_t amount_written() const
13410  {
13411  return amount_written_sofar_;
13412  }
13413 
13414  inline void clear()
13415  {
13416  reset();
13417  std::memset(buffer_,0x00,buffer_length_);
13418  }
13419 
13420  template <typename T, std::size_t N>
13421  inline bool operator()(const T (&data)[N], const bool write_length = false)
13422  {
13423  if (write_length && !operator()(N))
13424  return false;
13425 
13426  const std::size_t raw_size = N * sizeof(T);
13427  if (!buffer_capacity_ok(raw_size))
13428  return false;
13429 
13430  const char* ptr = reinterpret_cast<const char*>(data);
13431  std::copy(ptr, ptr + raw_size, buffer_);
13432  buffer_ += raw_size;
13433  amount_written_sofar_ += raw_size;
13434  return true;
13435  }
13436 
13437  template <typename T>
13438  inline bool operator()(const T* data, const uint32_t& length, const bool write_length = true)
13439  {
13440  if (write_length && !operator()(length))
13441  return false;
13442 
13443  const std::size_t raw_size = length * sizeof(T);
13444  if (!buffer_capacity_ok(raw_size))
13445  return false;
13446 
13447  const char* ptr = reinterpret_cast<const char*>(data);
13448  std::copy(ptr, ptr + raw_size, buffer_);
13449  buffer_ += raw_size;
13450  amount_written_sofar_ += raw_size;
13451  return true;
13452  }
13453 
13454  template <typename T>
13455  inline bool operator()(const T* data, const uint64_t& length, const bool write_length = true)
13456  {
13457  return operator()(data,static_cast<uint32_t>(length),write_length);
13458  }
13459 
13460  template <typename T>
13461  inline bool operator()(const T* data, const uint16_t& length, const bool write_length = true)
13462  {
13463  return operator()(data,static_cast<uint32_t>(length),write_length);
13464  }
13465 
13466  template <typename T>
13467  inline bool operator()(const T* data, const uint8_t& length, const bool write_length = true)
13468  {
13469  return operator()(data,static_cast<uint32_t>(length),write_length);
13470  }
13471 
13472  template <typename T1, typename T2>
13473  inline bool operator()(const std::pair<T1,T2>& p)
13474  {
13475  if (!operator()(p.first))
13476  return false;
13477  if (!operator()(p.second))
13478  return false;
13479  return true;
13480  }
13481 
13482  inline bool operator()(const std::string& input)
13483  {
13484  return operator()<const char>(input.data(),static_cast<uint32_t>(input.size()));
13485  }
13486 
13487  template <typename T,
13488  typename Allocator,
13489  template <typename,typename> class Sequence>
13490  inline bool operator()(const Sequence<T,Allocator>& seq)
13491  {
13492  const uint32_t size = static_cast<uint32_t>(seq.size());
13493  if (!operator()(size))
13494  return false;
13495 
13496  typename Sequence<T,Allocator>::const_iterator itr = seq.begin();
13497  typename Sequence<T,Allocator>::const_iterator end = seq.end();
13498  while (end != itr)
13499  {
13500  if (!operator()(*itr))
13501  return false;
13502  ++itr;
13503  }
13504  return true;
13505  }
13506 
13507  template <typename T,
13508  typename Allocator>
13509  inline bool operator()(const std::vector<T,Allocator>& vec)
13510  {
13511  const uint32_t size = static_cast<uint32_t>(vec.size());
13512  const std::size_t raw_size = (size * sizeof(T));
13513  if (!buffer_capacity_ok(raw_size + sizeof(size)))
13514  return false;
13515  if (!operator()(size))
13516  return false;
13517  return selector<T>::type::batch_vector_writer(*this,raw_size,vec);
13518  }
13519 
13520  template <typename T,
13521  typename Comparator,
13522  typename Allocator>
13523  inline bool operator()(const std::set<T,Comparator,Allocator>& set)
13524  {
13525  const uint32_t size = static_cast<uint32_t>(set.size());
13526  if (!operator()(size))
13527  return false;
13528 
13529  const std::size_t raw_size = size * sizeof(T);
13530  if (!buffer_capacity_ok(raw_size))
13531  return false;
13532 
13533  typename std::set<T,Comparator,Allocator>::const_iterator itr = set.begin();
13534  typename std::set<T,Comparator,Allocator>::const_iterator end = set.end();
13535  while (end != itr)
13536  {
13537  if (!operator()(*itr))
13538  return false;
13539  ++itr;
13540  }
13541  return true;
13542  }
13543 
13544  template <typename T,
13545  typename Allocator,
13546  typename Comparator>
13547  inline bool operator()(const std::multiset<T,Allocator,Comparator>& multiset)
13548  {
13549  const uint32_t size = static_cast<uint32_t>(multiset.size());
13550  if (!operator()(size))
13551  return false;
13552 
13553  const std::size_t raw_size = size * sizeof(T);
13554  if (!buffer_capacity_ok(raw_size))
13555  return false;
13556 
13557  typename std::multiset<T,Allocator,Comparator>::const_iterator itr = multiset.begin();
13558  typename std::multiset<T,Allocator,Comparator>::const_iterator end = multiset.end();
13559  while (end != itr)
13560  {
13561  if (!operator()(*itr))
13562  return false;
13563  ++itr;
13564  }
13565  return true;
13566  }
13567 
13568  inline std::size_t operator()(std::ofstream& stream)
13569  {
13570  stream.write(original_buffer_,static_cast<std::streamsize>(amount_written_sofar_));
13571  return amount_written_sofar_;
13572  }
13573 
13574  template <typename T>
13575  inline bool operator()(const T& input)
13576  {
13577  return selector<T>::type::run(*this,input);
13578  }
13579 
13580  template <typename T>
13581  inline bool native_to_be(const T& input)
13582  {
13583  //From native to big-endian
13584  if (details::is_little_endian())
13585  {
13586  return operator()<T>(details::convert(input));
13587  }
13588  else
13589  return operator()<T>(input);
13590  }
13591 
13592  template <typename T>
13593  inline bool native_to_le(const T& input)
13594  {
13595  //From native to little-endian
13596  if (details::is_little_endian())
13597  return operator()<T>(input);
13598  else
13599  return operator()<T>(details::convert(input));
13600  }
13601 
13603  {
13604  right_padding = 0,
13605  left_padding = 1
13606  };
13607 
13608  template <typename T>
13609  inline bool operator()(const T& input,
13610  const std::size_t& size,
13611  const padding_mode pmode,
13612  const char padding = ' ')
13613  {
13614  if (amount_written_sofar_ + size <= buffer_length_)
13615  {
13616  std::string s;
13617  s.reserve(size);
13618  if (!strtk::type_to_string<T>(input,s))
13619  return false;
13620  else if (s.size() > size)
13621  return false;
13622  else if (s.size() < size)
13623  {
13624  if (right_padding == pmode)
13625  s.resize(size - s.size(),padding);
13626  else
13627  s = std::string(size - s.size(),padding) + s;
13628  }
13629  return operator()<const char>(s.data(),static_cast<uint32_t>(size),false);
13630  }
13631  else
13632  return false;
13633  }
13634 
13635  inline void mark()
13636  {
13637  marker_.mark(amount_written_sofar_,buffer_);
13638  }
13639 
13640  inline bool reset_to_mark()
13641  {
13642  return marker_.reset(amount_written_sofar_,buffer_);
13643  }
13644 
13645  private:
13646 
13647  writer();
13648  writer(const writer& s);
13649  writer& operator=(const writer& s);
13650 
13651  inline bool buffer_capacity_ok(const std::size_t& required_write_qty)
13652  {
13653  return ((required_write_qty + amount_written_sofar_) <= buffer_length_);
13654  }
13655 
13656  template <typename Type>
13657  struct selector
13658  {
13659  private:
13660 
13661  template <typename T, typename IsPOD>
13662  struct selector_impl
13663  {
13664  template <typename Writer>
13665  static inline bool run(Writer& w, const T& t)
13666  {
13667  return t(w);
13668  }
13669 
13670  template <typename Writer,
13671  typename Allocator>
13672  static inline bool batch_vector_writer(Writer& w,
13673  const std::size_t&,
13674  const std::vector<T,Allocator>& v)
13675  {
13676  for (std::size_t i = 0; i < v.size(); ++i)
13677  {
13678  if (w.operator()(v[i]))
13679  continue;
13680  else
13681  return false;
13682  }
13683  return true;
13684  }
13685  };
13686 
13687  template <typename T>
13688  struct selector_impl<T,strtk::details::yes_t>
13689  {
13690  template <typename Writer>
13691  static inline bool run(Writer& w, const T& t)
13692  {
13693  return w.write_pod(t);
13694  }
13695 
13696  template <typename Writer,
13697  typename Allocator>
13698  static inline bool batch_vector_writer(Writer& w,
13699  const std::size_t& raw_size,
13700  const std::vector<T,Allocator>& v)
13701  {
13702  const char* ptr = reinterpret_cast<const char*>(&v[0]);
13703  std::copy(ptr, ptr + raw_size, w.buffer_);
13704  w.buffer_ += raw_size;
13705  w.amount_written_sofar_ += raw_size;
13706  return true;
13707  }
13708  };
13709 
13710  public:
13711 
13712  typedef selector_impl<Type,typename strtk::details::is_pod<Type>::result_t> type;
13713  };
13714 
13715  template <typename T>
13716  inline bool write_pod(const T& data, const bool perform_buffer_capacity_check = true)
13717  {
13718  static const std::size_t data_length = sizeof(T);
13719  if (perform_buffer_capacity_check)
13720  {
13721  if ((data_length + amount_written_sofar_) > buffer_length_)
13722  {
13723  return false;
13724  }
13725  }
13726  *(reinterpret_cast<T*>(buffer_)) = data;
13727  buffer_ += data_length;
13728  amount_written_sofar_ += data_length;
13729  return true;
13730  }
13731 
13732  char* const original_buffer_;
13733  char* buffer_;
13734  std::size_t buffer_length_;
13735  std::size_t amount_written_sofar_;
13736  details::marker marker_;
13737  };
13738 
13739  #define strtk_binary_reader_begin()\
13740  bool operator()(strtk::binary::reader& reader)\
13741  { return true\
13742 
13743  #define strtk_binary_reader(T)\
13744  && reader(T)\
13745 
13746  #define strtk_binary_reader_end()\
13747  ;}\
13748 
13749  #define strtk_binary_writer_begin()\
13750  bool operator()(strtk::binary::writer& writer) const\
13751  { return true\
13752 
13753  #define strtk_binary_writer(T)\
13754  && writer(T)\
13755 
13756  #define strtk_binary_writer_end()\
13757  ;}\
13758 
13759  namespace details
13760  {
13761  template <typename size_type>
13763  {
13764  public:
13765 
13767  : s(0)
13768  {}
13769 
13771  : s(&str)
13772  {}
13773 
13774  inline void clear()
13775  {
13776  s = 0;
13777  }
13778 
13780  {
13781  s = &str;
13782  return *this;
13783  }
13784 
13785  inline bool operator()(reader& r)
13786  {
13787  if (0 == s)
13788  return false;
13789  size_type size = 0;
13790  if (!r(size))
13791  return false;
13792  s->resize(size);
13793  char* ptr = const_cast<char*>(s->data());
13794  strtk::binary::reader::uint32_t length = size;
13795  if (!r(ptr,length,false))
13796  return false;
13797  return true;
13798  }
13799 
13800  inline bool operator()(writer& w) const
13801  {
13802  if (0 == s)
13803  return false;
13804  if (s->size() > std::numeric_limits<size_type>::max())
13805  return false;
13806  const size_type size = static_cast<size_type>(s->size());
13807  if (!w(size))
13808  return false;
13809  if (!w(s->data(),size, false))
13810  return false;
13811  return true;
13812  }
13813 
13814  private:
13815 
13816  short_string_impl& operator=(const short_string_impl&);
13817  mutable std::string* s;
13818  };
13819  }
13820 
13823 
13824  } // namespace binary
13825 
13827  {
13828  public:
13829 
13830  template <typename InputIterator>
13831  inline ignore_token& operator=(const std::pair<InputIterator,InputIterator>&)
13832  {
13833  return (*this);
13834  }
13835 
13837  {
13838  return (*this);
13839  }
13840  };
13841 
13842  template <typename T>
13844  {
13845  // static_assert for T either int or unsigned int and alike (could use a concept)
13846  private:
13847 
13848  struct hex_value_check
13849  {
13850  inline bool operator()(const unsigned char c) const
13851  {
13852  return (('0' <= c) && (c <= '9')) ||
13853  (('A' <= c) && (c <= 'F')) ||
13854  (('a' <= c) && (c <= 'f'));
13855  }
13856 
13857  inline bool operator()(const char c) const
13858  {
13859  return (*this)(static_cast<unsigned char>(c));
13860  }
13861  };
13862 
13863  public:
13864 
13866  : valid_(false),
13867  t_(&t)
13868  {}
13869 
13871  : valid_(hns.valid),
13872  t_(hns.t_)
13873  {}
13874 
13876  {
13877  valid_ = hns.valid_;
13878  t_ = hns.t_;
13879  return (*this);
13880  }
13881 
13882  template <typename InputIterator>
13883  inline hex_to_number_sink& operator=(const std::pair<InputIterator,InputIterator>& s)
13884  {
13885  std::size_t offset = 0;
13886  const std::size_t size = std::distance(s.first,s.second);
13887  if ((size > 2) && ((*s.first) == '0') && (((*(s.first + 1)) == 'x') || ((*(s.first + 1)) == 'X')))
13888  offset = 2;
13889  if ((size - offset) > (2 * sizeof(T)))
13890  return (*this);
13891 
13892  const std::size_t buffer_size = 2 * sizeof(T);
13893  const std::size_t buffer_offset = ((size - offset) % 2);
13894  char buffer[buffer_size] = { '0' };
13895  if (!range_only_contains(hex_value_check(),s.first + offset,s.first + size))
13896  {
13897  valid_ = false;
13898  return (*this);
13899  }
13900 
13901  std::copy(s.first + offset, s.first + size, buffer + buffer_offset);
13902  (*t_) = 0;
13903  valid_= convert_hex_to_bin(buffer,
13904  buffer + (size - offset) + buffer_offset,
13905  reinterpret_cast<char*>(t_));
13906  reverse_bytes();
13907  return (*this);
13908  }
13909 
13911  {
13912  return this->operator =(std::make_pair(s.data(),s.data() + s.size()));
13913  }
13914 
13915  inline bool valid() const
13916  {
13917  return valid_;
13918  }
13919 
13920  private:
13921 
13922  inline void reverse_bytes()
13923  {
13924  unsigned char* itr1 = reinterpret_cast<unsigned char*>(t_);
13925  unsigned char* itr2 = itr1 + (sizeof(T) - 1);
13926  while (itr1 < itr2)
13927  {
13928  std::swap(*itr1,*itr2);
13929  ++itr1;
13930  --itr2;
13931  }
13932  }
13933 
13934  private:
13935 
13936  bool valid_;
13937  T* t_;
13938  };
13939 
13940  template <typename T>
13942  {
13943  // static_assert for T either int or unsigned int and alike (could use a concept)
13944  private:
13945 
13946  struct base64_value_check
13947  {
13948  inline bool operator()(const unsigned char c) const
13949  {
13950  return (('0' <= c) && (c <= '9')) ||
13951  (('A' <= c) && (c <= 'Z')) ||
13952  (('a' <= c) && (c <= 'z')) ||
13953  ('+' == c) ||
13954  ('/' == c) ||
13955  ('=' == c);
13956  }
13957 
13958  inline bool operator()(const char c) const
13959  {
13960  return (*this)(static_cast<unsigned char>(c));
13961  }
13962  };
13963 
13964  public:
13965 
13967  : valid_(false),
13968  t_(&t)
13969  {}
13970 
13972  : valid_(bns.valid),
13973  t_(bns.t_)
13974  {}
13975 
13977  {
13978  valid_ = bns.valid_;
13979  t_ = bns.t_;
13980  return (*this);
13981  }
13982 
13984  {
13985  if (!range_only_contains(base64_value_check(),s.data(),s.data() + s.size()))
13986  {
13987  valid_ = false;
13988  return (*this);
13989  }
13990 
13991  (*t_) = T(0);
13992  convert_base64_to_bin(s.data(),
13993  s.data() + s.size(),
13994  reinterpret_cast<char*>(t_));
13995  reverse_bytes();
13996  return (*this);
13997  }
13998 
13999  template <typename InputIterator>
14000  inline base64_to_number_sink& operator=(const std::pair<InputIterator,InputIterator>& s)
14001  {
14002  if (!range_only_contains(base64_value_check(),s.first,s.second))
14003  {
14004  valid_ = false;
14005  return (*this);
14006  }
14007 
14008  (*t_) = T(0);
14009  convert_base64_to_bin(s.first, s.second,reinterpret_cast<char*>(t_));
14010  reverse_bytes();
14011  return (*this);
14012  }
14013 
14014  inline bool valid() const
14015  {
14016  return valid_;
14017  }
14018 
14019  private:
14020 
14021  inline void reverse_bytes()
14022  {
14023  unsigned char* itr1 = reinterpret_cast<unsigned char*>(t_);
14024  unsigned char* itr2 = itr1 + (sizeof(T) - 1);
14025  while (itr1 < itr2)
14026  {
14027  std::swap(*itr1,*itr2);
14028  ++itr1;
14029  --itr2;
14030  }
14031  }
14032 
14033  private:
14034 
14035  bool valid_;
14036  T* t_;
14037  };
14038 
14040  {
14041  public:
14042 
14044  : valid_(false),
14045  s_(s)
14046  {}
14047 
14049  : valid_(hss.valid_),
14050  s_(hss.s_)
14051  {}
14052 
14054  {
14055  valid_ = hss.valid_;
14056  s_ = hss.s_;
14057  return (*this);
14058  }
14059 
14060  template <typename InputIterator>
14061  inline hex_to_string_sink& operator=(const std::pair<InputIterator,InputIterator>& s)
14062  {
14063  const std::size_t size = std::distance(s.first,s.second);
14064  std::size_t offset = 0;
14065  if ((size > 2) && ((*s.first) == '0') && (((*(s.first + 1)) == 'x') || ((*(s.first + 1)) == 'X')))
14066  offset = 2;
14067  if ((size - offset) < 2)
14068  {
14069  valid_ = false;
14070  return (*this);
14071  }
14072  s_.resize((size - offset) / 2);
14073  valid_ = convert_hex_to_bin(s.first + offset,
14074  s.second,
14075  const_cast<char*>(s_.data()));
14076  return (*this);
14077  }
14078 
14080  {
14081  return this->operator=(std::make_pair<char*>(const_cast<char*>(s.data()),
14082  const_cast<char*>(s.data() + s.size())));
14083  }
14084 
14085  inline bool valid() const
14086  {
14087  return valid_;
14088  }
14089 
14090  private:
14091 
14092  bool valid_;
14093  std::string& s_;
14094  };
14095 
14096  namespace details
14097  {
14098 
14099  template <typename InputIterator,
14100  typename T,
14101  typename Allocator,
14102  template <typename,typename> class Sequence>
14103  inline std::size_t parse_stl_container_proxy(const InputIterator begin,
14104  const InputIterator end,
14105  const std::string& delimiters,
14106  Sequence<T,Allocator>& sequence,
14108  {
14109  return parse(begin,end,delimiters,sequence,split_option);
14110  }
14111 
14112  template <typename InputIterator,
14113  typename T,
14114  typename Comparator,
14115  typename Allocator>
14116  inline std::size_t parse_stl_container_proxy(const InputIterator begin,
14117  const InputIterator end,
14118  const std::string& delimiters,
14119  std::set<T,Comparator,Allocator>& set,
14121  {
14122  return parse(begin,end,delimiters,set,split_option);
14123  }
14124 
14125  template <typename InputIterator,
14126  typename T,
14127  typename Comparator,
14128  typename Allocator>
14129  inline std::size_t parse_stl_container_proxy(const InputIterator begin,
14130  const InputIterator end,
14131  const std::string& delimiters,
14132  std::multiset<T,Comparator,Allocator>& multiset,
14134  {
14135  return parse(begin,end,delimiters,multiset,split_option);
14136  }
14137 
14138  template <typename InputIterator,
14139  typename T,
14140  typename Container>
14141  inline std::size_t parse_stl_container_proxy(const InputIterator begin,
14142  const InputIterator end,
14143  const std::string& delimiters,
14144  std::queue<T,Container>& queue,
14146  {
14147  return parse(begin,end,delimiters,queue,split_option);
14148  }
14149 
14150  template <typename InputIterator,
14151  typename T,
14152  typename Container>
14153  inline std::size_t parse_stl_container_proxy(const InputIterator begin,
14154  const InputIterator end,
14155  const std::string& delimiters,
14156  std::stack<T,Container>& stack,
14158  {
14159  return parse(begin,end,delimiters,stack,split_option);
14160  }
14161 
14162  template <typename InputIterator,
14163  typename T,
14164  typename Container,
14165  typename Comparator>
14166  inline std::size_t parse_stl_container_proxy(const InputIterator begin,
14167  const InputIterator end,
14168  const std::string& delimiters,
14169  std::priority_queue<T,Container,Comparator>& priority_queue,
14171  {
14172  return parse(begin,end,delimiters,priority_queue,split_option);
14173  }
14174 
14175  template <typename InputIterator,
14176  typename T,
14177  typename Allocator,
14178  template <typename,typename> class Sequence>
14179  inline std::size_t parse_n_stl_container_proxy(const InputIterator begin,
14180  const InputIterator end,
14181  const std::string& delimiters,
14182  const std::size_t& n,
14183  Sequence<T,Allocator>& sequence,
14185  {
14186  return parse_n(begin,end,delimiters,n,sequence,split_option);
14187  }
14188 
14189  template <typename InputIterator,
14190  typename T,
14191  typename Comparator,
14192  typename Allocator>
14193  inline std::size_t parse_n_stl_container_proxy(const InputIterator begin,
14194  const InputIterator end,
14195  const std::string& delimiters,
14196  const std::size_t& n,
14197  std::set<T,Comparator,Allocator>& set,
14199  {
14200  return parse_n(begin,end,delimiters,n,set,split_option);
14201  }
14202 
14203  template <typename InputIterator,
14204  typename T,
14205  typename Comparator,
14206  typename Allocator>
14207  inline std::size_t parse_n_stl_container_proxy(const InputIterator begin,
14208  const InputIterator end,
14209  const std::string& delimiters,
14210  const std::size_t& n,
14211  std::multiset<T,Comparator,Allocator>& multiset,
14213  {
14214  return parse_n(begin,end,delimiters,n,multiset,split_option);
14215  }
14216 
14217  template <typename InputIterator,
14218  typename T,
14219  typename Container>
14220  inline std::size_t parse_n_stl_container_proxy(const InputIterator begin,
14221  const InputIterator end,
14222  const std::string& delimiters,
14223  const std::size_t& n,
14224  std::queue<T,Container>& queue,
14226  {
14227  return parse_n(begin,end,delimiters,n,queue,split_option);
14228  }
14229 
14230  template <typename InputIterator,
14231  typename T,
14232  typename Container>
14233  inline std::size_t parse_n_stl_container_proxy(const InputIterator begin,
14234  const InputIterator end,
14235  const std::string& delimiters,
14236  const std::size_t& n,
14237  std::stack<T,Container>& stack,
14239  {
14240  return parse_n(begin,end,delimiters,n,stack,split_option);
14241  }
14242 
14243  template <typename InputIterator,
14244  typename T,
14245  typename Container,
14246  typename Comparator>
14247  inline std::size_t parse_n_stl_container_proxy(const InputIterator begin,
14248  const InputIterator end,
14249  const std::string& delimiters,
14250  const std::size_t& n,
14251  std::priority_queue<T,Container,Comparator>& priority_queue,
14253  {
14254  return parse_n(begin,end,delimiters,n,priority_queue,split_option);
14255  }
14256 
14257  } // namespace details
14258 
14259  template <typename Container>
14261  {
14262  public:
14263 
14264  typedef typename Container::value_type value_type;
14265 
14266  inline sink_type(const std::string& delimiters,
14268  : delimiters_(delimiters),
14269  split_option_(split_option),
14270  container_(0),
14271  element_count_(std::numeric_limits<std::size_t>::max())
14272  {}
14273 
14274  inline sink_type(Container& container,
14275  const std::string& delimiters,
14277  : delimiters_(delimiters),
14278  split_option_(split_option),
14279  container_(&container)
14280  {}
14281 
14282  inline sink_type& count(const std::size_t& element_count = std::numeric_limits<std::size_t>::max())
14283  {
14284  element_count_ = element_count;
14285  return (*this);
14286  }
14287 
14288  inline sink_type& operator()(Container& container,
14289  const std::string& delimiters = "",
14291  {
14292  container_ = (&container);
14293  if (!delimiters.empty())
14294  delimiters_ = delimiters;
14295  split_option_ = split_option;
14296  return (*this);
14297  }
14298 
14299  template <typename InputIterator>
14300  inline bool parse(InputIterator begin, InputIterator end)
14301  {
14302  if (container_)
14303  {
14304  if (std::numeric_limits<std::size_t>::max() == element_count_)
14306  (begin,end,delimiters_,(*container_),split_option_) > 0);
14307  else
14309  (begin,end,delimiters_,element_count_,(*container_),split_option_) == element_count_);
14310  }
14311  else
14312  return false;
14313  }
14314 
14316  {
14317  return *this;
14318  }
14319 
14320  private:
14321 
14322  std::string delimiters_;
14323  split_options::type split_option_;
14324  Container* container_;
14325  std::size_t element_count_;
14326  };
14327 
14328  template <typename T> struct vector_sink { typedef sink_type<std::vector<T> > type; };
14329  template <typename T> struct deque_sink { typedef sink_type<std::deque<T> > type; };
14330  template <typename T> struct list_sink { typedef sink_type<std::list<T> > type; };
14331  template <typename T> struct set_sink { typedef sink_type<std::set<T> > type; };
14332  template <typename T> struct multiset_sink { typedef sink_type<std::multiset<T> > type; };
14333  template <typename T> struct queue_sink { typedef sink_type<std::queue<T> > type; };
14334  template <typename T> struct stack_sink { typedef sink_type<std::stack<T> > type; };
14335  template <typename T> struct priority_queue_sink { typedef sink_type<std::priority_queue<T> > type; };
14336 
14337  namespace text
14338  {
14339  inline std::string center(const std::size_t& width,
14340  const std::string::value_type& pad,
14341  const std::string& str)
14342  {
14343  if (str.size() >= width) return str;
14344  const std::size_t pad_count = width - str.size();
14345  const std::size_t pad_count_2 = (pad_count >> 1) + (pad_count & 1);
14346  return std::string(pad_count >> 1,pad) + str + std::string(pad_count_2,pad);
14347  }
14348 
14349  inline std::string right_align(const std::size_t& width,
14350  const std::string::value_type& pad,
14351  const std::string& str)
14352  {
14353  if (str.size() >= width) return str;
14354  return std::string(width - str.size(),pad) + str;
14355  }
14356 
14357  inline std::string left_align(const std::size_t& width,
14358  const std::string::value_type& pad,
14359  const std::string& str)
14360  {
14361  if (str.size() >= width) return str;
14362  return str + std::string(width - str.size(),pad);
14363  }
14364 
14365  template <typename T>
14366  inline std::string center(const std::size_t& width,
14367  const std::string::value_type& pad,
14368  const T& t)
14369  {
14370  return center(width,pad,type_to_string(t));
14371  }
14372 
14373  template <typename T>
14374  inline std::string right_align(const std::size_t& width,
14375  const std::string::value_type& pad,
14376  const T& t)
14377  {
14378  return right_align(width,pad,type_to_string(t));
14379  }
14380 
14381  template <typename T>
14382  inline std::string left_align(const std::size_t& width,
14383  const std::string::value_type& pad,
14384  const T& t)
14385  {
14386  return left_align(width,pad,type_to_string(t));
14387  }
14388 
14389  template <typename T>
14390  inline std::string center(const std::size_t& width, const T& t)
14391  {
14392  return center(width,' ',type_to_string(t));
14393  }
14394 
14395  template <typename T>
14396  inline std::string right_align(const std::size_t& width, const T& t)
14397  {
14398  return right_align(width,' ',type_to_string(t));
14399  }
14400 
14401  template <typename T>
14402  inline std::string left_align(const std::size_t& width, const T& t)
14403  {
14404  return left_align(width,' ',type_to_string(t));
14405  }
14406 
14407  inline std::string remaining_string(const std::size_t& index,
14408  const std::string& str)
14409  {
14410  return (index < str.size()) ? str.substr(index,str.size() - index) : str;
14411  }
14412 
14413  inline void remaining_string(const std::size_t& index,
14414  const std::string& str,
14415  std::string& result)
14416  {
14417  result = (index < str.size()) ? str.substr(index,str.size() - index) : str;
14418  }
14419 
14420  inline bool is_letter(const char c)
14421  {
14422  return (('A' <= c) && ( c <= 'Z')) || (('a' <= c) && ( c <= 'z'));
14423  }
14424 
14425  inline bool is_lowercase_letter(const char c)
14426  {
14427  return (('a' <= c) && ( c <= 'z'));
14428  }
14429 
14430  inline bool is_uppercase_letter(const char c)
14431  {
14432  return (('A' <= c) && ( c <= 'Z'));
14433  }
14434 
14435  inline bool is_digit(const char c)
14436  {
14437  return (('0' <= c) && ( c <= '9'));
14438  }
14439 
14440  inline bool is_hex_digit(const char c)
14441  {
14442  return (('0' <= c) && (c <= '9')) ||
14443  (('A' <= c) && (c <= 'F')) ||
14444  (('a' <= c) && (c <= 'f'));
14445  }
14446 
14447  inline bool is_letter_or_digit(const char c)
14448  {
14449  return (is_letter(c) || is_digit(c));
14450  }
14451 
14452  inline bool is_all_letters(const std::string& s)
14453  {
14454  for (std::size_t i = 0; i < s.size(); ++i)
14455  {
14456  if (!is_letter(s[i]))
14457  return false;
14458  }
14459  return true;
14460  }
14461 
14462  inline bool is_all_digits(const std::string& s)
14463  {
14464  for (std::size_t i = 0; i < s.size(); ++i)
14465  {
14466  if (!is_digit(s[i]))
14467  return false;
14468  }
14469  return true;
14470  }
14471 
14472  inline void swap_inplace(std::string& s, const std::size_t& i0, const std::size_t& i1)
14473  {
14474  if (i0 >= s.size()) return;
14475  if (i1 >= s.size()) return;
14476  std::swap(s[i0],s[i1]);
14477  }
14478 
14479  inline std::string swap(const std::string& s, const std::size_t& i0, const std::size_t& i1)
14480  {
14481  std::string result = s;
14482  swap_inplace(result,i0,i1);
14483  return result;
14484  }
14485 
14486  inline void remove_inplace(std::string& s, const std::size_t& index)
14487  {
14488  if (index >= s.size())
14489  return;
14490  std::memcpy(const_cast<char*>(s.data() + index), const_cast<char*>(s.data() + (index + 1)), s.size() - index);
14491  s.resize(s.size() - 1);
14492  }
14493 
14494  inline std::string remove(const std::string& s, const std::size_t& index)
14495  {
14496  std::string result = s;
14497  remove_inplace(result,index);
14498  return result;
14499  }
14500 
14501  inline void insert_inplace(std::string& s, const std::size_t& index, const char c)
14502  {
14503  s.resize(s.size() + 1);
14504  std::memcpy(const_cast<char*>(s.data() + index + 1), const_cast<char*>(s.data() + (index)), s.size() - index);
14505  s[index] = c;
14506  }
14507 
14508  inline std::string insert(const std::string& s, const std::size_t& index, const char c)
14509  {
14510  std::string result = s;
14511  insert_inplace(result,index,c);
14512  return result;
14513  }
14514 
14515  } // namespace text
14516 
14517  namespace find_mode
14518  {
14519  enum type
14520  {
14523  };
14524  }
14525 
14526  namespace find_type
14527  {
14528  enum type
14529  {
14535  };
14536  }
14537 
14538  namespace details
14539  {
14540 
14541  template <typename Iterator>
14542  struct range_type
14543  {
14544  typedef typename std::pair<Iterator,Iterator> type;
14545  };
14546 
14547  template <typename Iterator, typename Predicate>
14549  Predicate p,
14550  Iterator itr,
14551  const Iterator end,
14552  const bool stateful_predicate = false)
14553  {
14554  if (static_cast<unsigned int>(std::distance(itr,end)) < n)
14555  return typename range_type<Iterator>::type(end,end);
14556  std::size_t count = n;
14557  while (end != itr)
14558  {
14559  if (p(*itr))
14560  {
14561  if (0 != --count)
14562  ++itr;
14563  else
14564  {
14565  std::advance(itr,1 - n);
14566  return typename range_type<Iterator>::type(itr,itr + n);
14567  }
14568  }
14569  else
14570  {
14571  ++itr;
14572  while ((end != itr) && !p(*itr))
14573  ++itr;
14574  if (!stateful_predicate)
14575  count = n;
14576  else
14577  {
14578  --count;
14579  ++itr;
14580  }
14581  }
14582  }
14583  return typename range_type<Iterator>::type(end,end);
14584  }
14585 
14586  template <typename Iterator, typename Predicate>
14588  Predicate p,
14589  Iterator itr,
14590  const Iterator end)
14591  {
14592  if (static_cast<unsigned int>(std::distance(itr,end)) < n)
14593  return typename range_type<Iterator>::type(end,end);
14594  std::size_t count = 0;
14595  while (end != itr)
14596  {
14597  if (p(*itr))
14598  {
14599  ++count;
14600  ++itr;
14601  }
14602  else
14603  {
14604  if (count >= n)
14605  {
14606  std::advance(itr,-static_cast<int>(count));
14607  return typename range_type<Iterator>::type(itr,itr + count);
14608  }
14609  while ((end != itr) && !p(*itr))
14610  ++itr;
14611  count = 0;
14612  }
14613  }
14614  if (count >= n)
14615  {
14616  std::advance(itr,-static_cast<int>(count));
14617  return typename range_type<Iterator>::type(itr,itr + count);
14618  }
14619  else
14620  return typename range_type<Iterator>::type(end,end);
14621  }
14622 
14623  template <typename Iterator, typename Predicate>
14625  Predicate p,
14626  typename details::range_type<Iterator>::type range,
14627  const bool stateful_predicate = false)
14628  {
14629  return find_exactly_n_consecutive_values(n,p,range.first,range.second,stateful_predicate);
14630  }
14631 
14632  template <typename Iterator, typename Predicate>
14634  Predicate p,
14635  typename details::range_type<Iterator>::type range)
14636  {
14637  return find_atleast_n_consecutive_values(n,p,range.first,range.second);
14638  }
14639 
14640  template <typename Iterator, typename Predicate>
14641  inline typename range_type<Iterator>::type find_n_consecutive_values(const std::size_t n,
14642  find_mode::type mode,
14643  Predicate p,
14644  Iterator itr,
14645  const Iterator end)
14646  {
14647  switch (mode)
14648  {
14649  case find_mode::exactly_n : return find_exactly_n_consecutive_values(n,p,itr,end);
14650  case find_mode::atleast_n : return find_atleast_n_consecutive_values(n,p,itr,end);
14651  default : return typename range_type<Iterator>::type(end,end);
14652  }
14653  }
14654 
14655  template <typename Iterator,typename Predicate>
14656  inline bool match_exactly_n_consecutive_values(const std::size_t n,
14657  Predicate p,
14658  Iterator itr,
14659  const Iterator end)
14660  {
14661  if (static_cast<unsigned int>(std::distance(itr,end)) < n)
14662  return false;
14663  std::size_t count = n;
14664  while (end != itr)
14665  {
14666  if (p(*itr))
14667  {
14668  if (0 == --count)
14669  return true;
14670  else
14671  ++itr;
14672  }
14673  else
14674  return false;
14675  }
14676  return false;
14677  }
14678 
14679  template <typename Iterator,typename Predicate>
14680  inline bool match_atleast_n_consecutive_values(const std::size_t n,
14681  Predicate p,
14682  Iterator itr,
14683  const Iterator end)
14684  {
14685  if (static_cast<unsigned int>(std::distance(itr,end)) < n)
14686  return false;
14687  std::size_t count = 0;
14688  while (end != itr)
14689  {
14690  if (p(*itr))
14691  {
14692  ++count;
14693  ++itr;
14694  }
14695  else if (count >= n)
14696  return true;
14697  else
14698  return false;
14699  }
14700  return false;
14701  }
14702 
14703  template <typename Iterator,typename Predicate>
14704  inline bool match_n_consecutive_values(const std::size_t n,
14705  find_mode::type mode,
14706  Predicate p,
14707  Iterator itr,
14708  const Iterator end)
14709  {
14710  switch (mode)
14711  {
14712  case find_mode::exactly_n : return match_exactly_n_consecutive_values(n,p,itr,end);
14713  case find_mode::atleast_n : return match_atleast_n_consecutive_values(n,p,itr,end);
14714  default : return false;
14715  }
14716  }
14717 
14718  }
14719 
14720  template <typename Iterator>
14721  inline typename details::range_type<Iterator>::type find_n_consecutive(const std::size_t n,
14723  find_mode::type mode,
14724  typename details::range_type<Iterator>::type range)
14725  {
14726  switch (type)
14727  {
14728  case find_type::digits : return details::find_n_consecutive_values<Iterator>(n,
14729  mode,
14731  range.first,range.second);
14732 
14733  case find_type::letters : return details::find_n_consecutive_values<Iterator>(n,
14734  mode,
14736  range.first,range.second);
14737 
14738  case find_type::lowercase_letters : return details::find_n_consecutive_values<Iterator>(n,
14739  mode,
14741  range.first,range.second);
14742 
14743  case find_type::uppercase_letters : return details::find_n_consecutive_values<Iterator>(n,
14744  mode,
14746  range.first,range.second);
14747 
14748  case find_type::letters_digits : return details::find_n_consecutive_values<Iterator>(n,
14749  mode,
14751  range.first,range.second);
14752 
14753  default : return typename details::range_type<Iterator>::type(range.second,range.second);
14754  }
14755  }
14756 
14757  template <typename Iterator>
14758  inline bool match_n_consecutive(const std::size_t n,
14760  find_mode::type mode,
14761  typename details::range_type<Iterator>::type range)
14762  {
14763  switch (type)
14764  {
14765  case find_type::digits : return details::match_n_consecutive_values<Iterator>(n,
14766  mode,
14768  range.first,range.second);
14769 
14770  case find_type::letters : return details::match_n_consecutive_values<Iterator>(n,
14771  mode,
14773  range.first,range.second);
14774 
14775  case find_type::lowercase_letters : return details::match_n_consecutive_values<Iterator>(n,
14776  mode,
14778  range.first,range.second);
14779 
14780  case find_type::uppercase_letters : return details::match_n_consecutive_values<Iterator>(n,
14781  mode,
14783  range.first,range.second);
14784 
14785  case find_type::letters_digits : return details::match_n_consecutive_values<Iterator>(n,
14786  mode,
14788  range.first,range.second);
14789 
14790  default : return false;
14791  }
14792  }
14793 
14794  template <typename Predicate,
14795  typename OutputIterator>
14796  inline std::size_t split_on_consecutive(const std::size_t n,
14797  Predicate p,
14798  char* begin,
14799  char* end,
14800  OutputIterator out,
14801  const bool stateful_predicate = false)
14802  {
14803  if (0 == n) return 0;
14804  typedef char* iterator_type;
14805  typedef details::range_type<iterator_type>::type range_type;
14806  range_type itr_range(begin,end);
14807  std::size_t match_count = 0;
14808  while (end != itr_range.first)
14809  {
14810  range_type found_itr =
14811  details::find_exactly_n_consecutive_values<iterator_type,Predicate>(n,
14812  p,
14813  itr_range,
14814  stateful_predicate);
14815 
14816  if ((end == found_itr.first) && (found_itr.first == found_itr.second))
14817  {
14818  break;
14819  }
14820  else
14821  {
14822  (*out) = found_itr;
14823  ++out;
14824  ++match_count;
14825  itr_range.first = found_itr.second;
14826  }
14827  }
14828  return match_count;
14829  }
14830 
14831  template <typename Predicate,
14832  typename OutputIterator>
14833  inline std::size_t split_on_consecutive(const std::size_t n,
14834  const std::size_t m,
14835  Predicate p,
14836  char* begin,
14837  char* end,
14838  OutputIterator out)
14839  {
14840  if (0 == n) return 0;
14841  typedef char* iterator_type;
14842  typedef details::range_type<iterator_type>::type range_type;
14843  range_type itr_range(begin,end);
14844  std::size_t match_count = 0;
14845  while ((end != itr_range.first) && (match_count <= n))
14846  {
14847  range_type found_itr = details::find_exactly_n_consecutive_values(m,p,itr_range);
14848  if ((end == found_itr.first) && (found_itr.first == found_itr.second))
14849  {
14850  break;
14851  }
14852  else
14853  {
14854  (*out) = found_itr;
14855  ++out;
14856  ++match_count;
14857  itr_range.first = found_itr.second;
14858  }
14859  }
14860  return match_count;
14861  }
14862 
14863  template <typename InputIterator, typename OutputIterator>
14864  inline std::size_t split_on_consecutive(const std::size_t& n,
14865  const find_type::type type,
14866  const find_mode::type mode,
14867  char* begin,
14868  char* end,
14869  OutputIterator out)
14870  {
14871  if (0 == n) return 0;
14872  typedef char* iterator_type;
14873  typedef details::range_type<iterator_type>::type range_type;
14874  range_type itr_range(begin,end);
14875  std::size_t match_count = 0;
14876  while (end != itr_range.first)
14877  {
14878  range_type found_itr = find_n_consecutive<iterator_type>(n,type,mode,itr_range);
14879  if ((end == found_itr.first) && (found_itr.first == found_itr.second))
14880  {
14881  break;
14882  }
14883  else
14884  {
14885  (*out) = found_itr;
14886  ++out;
14887  ++match_count;
14888  itr_range.first = found_itr.second;
14889  }
14890  }
14891  return match_count;
14892  }
14893 
14894  template <typename InputIterator, typename OutputIterator>
14895  inline std::size_t split_on_consecutive_n(const std::size_t& n,
14896  const std::size_t& m,
14897  const find_type::type type,
14898  const find_mode::type mode,
14899  char* begin,
14900  char* end,
14901  OutputIterator out)
14902  {
14903  if (0 == n) return 0;
14904  typedef char* iterator_type;
14905  typedef details::range_type<iterator_type>::type range_type;
14906  range_type itr_range(begin,end);
14907  std::size_t match_count = 0;
14908  while ((end != itr_range.first) && (match_count <= n))
14909  {
14910  range_type found_itr = find_n_consecutive<iterator_type>(m,type,mode,itr_range);
14911  if ((end == found_itr.first) && (found_itr.first == found_itr.second))
14912  {
14913  break;
14914  }
14915  else
14916  {
14917  (*out) = found_itr;
14918  ++out;
14919  ++match_count;
14920  itr_range.first = found_itr.second;
14921  }
14922  }
14923  return match_count;
14924  }
14925 
14926  template <typename OutputIterator>
14927  inline std::size_t split_on_consecutive(const std::size_t& n,
14928  const find_type::type type,
14929  const find_mode::type mode,
14930  const char* begin,
14931  const char* end,
14932  OutputIterator out)
14933  {
14934  return split_on_consecutive<char*,OutputIterator>(n,
14935  type,
14936  mode,
14937  const_cast<char*>(begin),
14938  const_cast<char*>(end),
14939  out);
14940  }
14941 
14942  template <typename OutputIterator>
14943  inline std::size_t split_on_consecutive(const std::size_t& n,
14944  const find_type::type type,
14945  const find_mode::type mode,
14946  const unsigned char* begin,
14947  const unsigned char* end,
14948  OutputIterator out)
14949  {
14950  return split_on_consecutive<OutputIterator>(n,
14951  type,
14952  mode,
14953  reinterpret_cast<const char*>(begin),
14954  reinterpret_cast<const char*>(end),
14955  out);
14956  }
14957 
14958  template <typename OutputIterator>
14959  inline std::size_t split_on_consecutive(const std::size_t& n,
14960  const find_type::type type,
14961  const find_mode::type mode,
14962  const std::string& str,
14963  OutputIterator out)
14964  {
14965  return split_on_consecutive<OutputIterator>(n,
14966  type,
14967  mode,
14968  str.data(),
14969  str.data() + str.size(),
14970  out);
14971  }
14972 
14973  template <typename OutputIterator>
14974  inline std::size_t split_on_consecutive_n(const std::size_t& n,
14975  const std::size_t& m,
14976  const find_type::type type,
14977  const find_mode::type mode,
14978  const char* begin,
14979  const char* end,
14980  OutputIterator out)
14981  {
14982  return split_on_consecutive_n<char*,OutputIterator>(n,
14983  m,
14984  type,
14985  mode,
14986  const_cast<char*>(begin),
14987  const_cast<char*>(end),
14988  out);
14989  }
14990 
14991  template <typename OutputIterator>
14992  inline std::size_t split_on_consecutive_n(const std::size_t& n,
14993  const std::size_t& m,
14994  const find_type::type type,
14995  const find_mode::type mode,
14996  const unsigned char* begin,
14997  const unsigned char* end,
14998  OutputIterator out)
14999  {
15000  return split_on_consecutive_n<OutputIterator>(n,
15001  m,
15002  type,
15003  mode,
15004  reinterpret_cast<const char*>(begin),
15005  reinterpret_cast<const char*>(end),
15006  out);
15007  }
15008 
15009  template <typename OutputIterator>
15010  inline std::size_t split_on_consecutive_n(const std::size_t& n,
15011  const std::size_t& m,
15012  const find_type::type type,
15013  const find_mode::type mode,
15014  const std::string& str,
15015  OutputIterator out)
15016  {
15017  return split_on_consecutive_n<OutputIterator>(n,
15018  m,
15019  type,
15020  mode,
15021  str.data(),
15022  str.data() + str.size(),
15023  out);
15024  }
15025 
15026  template <typename Predicate, typename OutputIterator>
15027  inline std::size_t split_on_consecutive(const std::size_t& n,
15028  Predicate p,
15029  const char* begin,
15030  const char* end,
15031  OutputIterator out,
15032  const bool stateful_predicate = false)
15033  {
15034  return split_on_consecutive<Predicate,
15035  OutputIterator>(n,
15036  p,
15037  const_cast<char*>(begin),
15038  const_cast<char*>(end),
15039  out,
15040  stateful_predicate);
15041  }
15042 
15043  template <typename Predicate, typename OutputIterator>
15044  inline std::size_t split_on_consecutive(const std::size_t& n,
15045  Predicate p,
15046  const unsigned char* begin,
15047  const unsigned char* end,
15048  OutputIterator out,
15049  const bool stateful_predicate = false)
15050  {
15051  return split_on_consecutive<Predicate,
15052  OutputIterator>(n,
15053  p,
15054  reinterpret_cast<const char*>(begin),
15055  reinterpret_cast<const char*>(end),
15056  out,
15057  stateful_predicate);
15058  }
15059 
15060  template <typename Predicate, typename OutputIterator>
15061  inline std::size_t split_on_consecutive(const std::size_t& n,
15062  Predicate p,
15063  const std::string& str,
15064  OutputIterator out,
15065  const bool stateful_predicate = false)
15066  {
15067  return split_on_consecutive<Predicate,
15068  OutputIterator>(n,
15069  p,
15070  str.data(),
15071  str.data() + str.size(),
15072  out,
15073  stateful_predicate);
15074  }
15075 
15076  template <typename Predicate, typename OutputIterator>
15077  inline std::size_t split_on_consecutive_n(const std::size_t& n,
15078  const std::size_t& m,
15079  Predicate p,
15080  const char* begin,
15081  const char* end,
15082  OutputIterator out)
15083  {
15084  return split_on_consecutive_n<Predicate,
15085  char*,
15086  OutputIterator>(n,
15087  m,
15088  p,
15089  const_cast<char*>(begin),
15090  const_cast<char*>(end),
15091  out);
15092  }
15093 
15094  template <typename Predicate, typename OutputIterator>
15095  inline std::size_t split_on_consecutive_n(const std::size_t& n,
15096  const std::size_t& m,
15097  Predicate p,
15098  const unsigned char* begin,
15099  const unsigned char* end,
15100  OutputIterator out)
15101  {
15102  return split_on_consecutive_n<Predicate,
15103  OutputIterator>(n,
15104  m,
15105  p,
15106  reinterpret_cast<const char*>(begin),
15107  reinterpret_cast<const char*>(end),
15108  out);
15109  }
15110 
15111  template <typename Predicate, typename OutputIterator>
15112  inline std::size_t split_on_consecutive_n(const std::size_t& n,
15113  const std::size_t& m,
15114  Predicate p,
15115  const std::string& str,
15116  OutputIterator out)
15117  {
15118  return split_on_consecutive_n<Predicate,
15119  OutputIterator>(n,
15120  m,
15121  p,
15122  str.data(),
15123  str.data() + str.size(),
15124  out);
15125  }
15126 
15127  // Required for broken versions of GCC pre 4.5
15128  namespace util { class value; }
15129 
15130  namespace details
15131  {
15132 
15134  {
15135  public:
15136 
15138  : s_(s)
15139  {}
15140 
15141  template <typename InputIterator>
15142  inline bool operator()(InputIterator begin, InputIterator end)
15143  {
15144  if (static_cast<std::size_t>(std::distance(begin,end)) != s_.size())
15145  return false;
15146  else
15147  return std::equal(s_.data(),s_.data() + s_.size(),begin);
15148  }
15149 
15150  inline expect_impl& ref()
15151  {
15152  return (*this);
15153  }
15154 
15155  inline void set_value(const std::string& s)
15156  {
15157  s_ = s;
15158  }
15159 
15160  private:
15161 
15162  std::string s_;
15163  };
15164 
15166  {
15167  public:
15168 
15170  : s_(s)
15171  {}
15172 
15173  template <typename InputIterator>
15174  inline bool operator()(InputIterator begin, InputIterator end)
15175  {
15176  if (static_cast<std::size_t>(std::distance(begin,end)) != s_.size())
15177  return false;
15178  else
15179  return std::equal(s_.data(),s_.data() + s_.size(),begin,imatch_char);
15180  }
15181 
15182  inline iexpect_impl& ref()
15183  {
15184  return (*this);
15185  }
15186 
15187  inline void set_value(const std::string& s)
15188  {
15189  s_ = s;
15190  }
15191 
15192  private:
15193 
15194  std::string s_;
15195  };
15196 
15198  {
15199  public:
15200 
15202  : s_(s)
15203  {}
15204 
15205  template <typename InputIterator>
15206  inline bool operator()(InputIterator begin, InputIterator end)
15207  {
15208  typedef typename std::iterator_traits<InputIterator>::value_type value_type;
15209  static const value_type zero_or_more = value_type('*');
15210  static const value_type zero_or_one = value_type('?');
15211  return strtk::match(s_.data(),s_.data() + s_.size(),begin,end,zero_or_more,zero_or_one);
15212  }
15213 
15214  inline like_impl& ref()
15215  {
15216  return (*this);
15217  }
15218 
15219  inline void set_pattern(const std::string& s)
15220  {
15221  s_ = s;
15222  }
15223 
15224  private:
15225 
15226  std::string s_;
15227  };
15228 
15229  template <typename T>
15231  {
15232  public:
15233 
15234  inrange_impl(T& t, const T& low, const T& hi)
15235  : t_(&t),
15236  low_(low),
15237  hi_(hi)
15238  {}
15239 
15240  template <typename InputIterator>
15241  inline bool operator()(InputIterator begin, InputIterator end)
15242  {
15243  T temp;
15244  if (!strtk::string_to_type_converter(begin,end,temp))
15245  return false;
15246  else if (temp < low_)
15247  return false;
15248  else if (temp > hi_)
15249  return false;
15250  (*t_) = temp;
15251  return true;
15252  }
15253 
15255  {
15256  return (*this);
15257  }
15258 
15259  inline void set_low_hi(const T& low, const T& hi)
15260  {
15261  low_ = low;
15262  hi_ = hi;
15263  }
15264 
15265  private:
15266 
15267  T* t_;
15268  T low_;
15269  T hi_;
15270  };
15271 
15272  namespace trim_details
15273  {
15274  template <typename Type>
15276  {
15277  template <typename InputIterator>
15278  static bool execute(InputIterator begin, InputIterator end,
15279  const std::string& rem_chars,
15280  std::size_t mode,
15281  Type& t)
15282  {
15283  std::string s;
15284  if (!strtk::string_to_type_converter(begin,end,s))
15285  return false;
15286  switch (mode)
15287  {
15288  case 0 : remove_leading_trailing(rem_chars,s); break;
15289  case 1 : remove_leading (rem_chars,s); break;
15290  case 2 : remove_trailing (rem_chars,s); break;
15291  default : return false;
15292  }
15293  return strtk::string_to_type_converter(s,t);
15294  }
15295  };
15296 
15297  template <>
15298  struct convert_impl <std::string>
15299  {
15300  template <typename InputIterator>
15301  static bool execute(InputIterator begin, InputIterator end,
15302  const std::string& rem_chars,
15303  std::size_t mode,
15304  std::string& t)
15305  {
15306  if (!strtk::string_to_type_converter(begin,end,t))
15307  return false;
15308  switch (mode)
15309  {
15310  case 0 : remove_leading_trailing(rem_chars,t); break;
15311  case 1 : remove_leading (rem_chars,t); break;
15312  case 2 : remove_trailing (rem_chars,t); break;
15313  default : return false;
15314  }
15315  return true;
15316  }
15317  };
15318  }
15319 
15320  template <typename T>
15322  {
15323  public:
15324 
15325  trim_impl(const std::size_t mode,
15326  T& t,
15327  const std::string& rem_chars = " ")
15328  : mode_(mode),
15329  t_(&t),
15330  rem_chars_(rem_chars)
15331  {}
15332 
15333  template <typename InputIterator>
15334  inline bool operator()(InputIterator begin, InputIterator end)
15335  {
15336  return trim_details::convert_impl<T>::execute(begin,end,rem_chars_,mode_,(*t_));
15337  }
15338 
15339  inline trim_impl<T>& ref()
15340  {
15341  return (*this);
15342  }
15343 
15344  private:
15345 
15346  std::size_t mode_;
15347  T* t_;
15348  std::string rem_chars_;
15349  };
15350 
15352  {
15353  public:
15354 
15356  : s_(&s)
15357  {}
15358 
15359  template <typename InputIterator>
15360  inline bool operator()(InputIterator begin, InputIterator end)
15361  {
15362  std::string& s = (*s_);
15363  s.assign(begin,end);
15365  return true;
15366  }
15367 
15369  {
15370  return (*this);
15371  }
15372 
15373  private:
15374 
15375  std::string* s_;
15376  };
15377 
15379  {
15380  public:
15381 
15383  : s_(&s)
15384  {}
15385 
15386  template <typename InputIterator>
15387  inline bool operator()(InputIterator begin, InputIterator end)
15388  {
15389  std::string& s = (*s_);
15390  s.assign(begin,end);
15392  return true;
15393  }
15394 
15396  {
15397  return (*this);
15398  }
15399 
15400  private:
15401 
15402  std::string* s_;
15403  };
15404 
15406  {
15407  public:
15408 
15409  fill_array_impl(unsigned char* data, const std::size_t& size)
15410  : data_(data),
15411  size_(size)
15412  {}
15413 
15414  template <typename InputIterator>
15415  inline bool operator()(InputIterator begin, InputIterator end)
15416  {
15417  const std::size_t range_size = static_cast<std::size_t>(std::distance(begin,end));
15418  if (range_size != size_)
15419  return false;
15420  std::memcpy(data_,begin,range_size);
15421  return true;
15422  }
15423 
15425  {
15426  return (*this);
15427  }
15428 
15429  inline fill_array_impl& set(unsigned char* data, const std::size_t& size)
15430  {
15431  data_ = data;
15432  size_ = size;
15433  return (*this);
15434  }
15435 
15436  inline fill_array_impl& set(char* data, const std::size_t& size)
15437  {
15438  data_ = reinterpret_cast<unsigned char*>(data);
15439  size_ = size;
15440  return (*this);
15441  }
15442 
15443  inline fill_array_impl& set_data(unsigned char* data)
15444  {
15445  data_ = data;
15446  return (*this);
15447  }
15448 
15449  inline fill_array_impl& set_data(char* data)
15450  {
15451  data_ = reinterpret_cast<unsigned char*>(data);
15452  return (*this);
15453  }
15454 
15455  inline fill_array_impl& set_size(const std::size_t& size)
15456  {
15457  size_ = size;
15458  return (*this);
15459  }
15460 
15461  private:
15462 
15463  unsigned char* data_;
15464  std::size_t size_;
15465  };
15466 
15467  }
15468 
15470  {
15471  return details::expect_impl(s);
15472  }
15473 
15475  {
15476  return details::iexpect_impl(s);
15477  }
15478 
15480  {
15481  return details::like_impl(s);
15482  }
15483 
15484  template <typename T, typename T0, typename T1>
15485  inline details::inrange_impl<T> inrange(T& t, const T0& low, const T1& hi)
15486  {
15487  return details::inrange_impl<T>(t,T(low),T(hi));
15488  }
15489 
15490  template <typename T>
15491  inline details::trim_impl<T> trim(const std::string& rem_chars, T& t)
15492  {
15493  return details::trim_impl<T>(0,t,rem_chars);
15494  }
15495 
15496  template <typename T>
15497  inline details::trim_impl<T> trim_leading(const std::string& rem_chars, T& t)
15498  {
15499  return details::trim_impl<T>(1,t,rem_chars);
15500  }
15501 
15502  template <typename T>
15503  inline details::trim_impl<T> trim_trailing(const std::string& rem_chars, T& t)
15504  {
15505  return details::trim_impl<T>(2,t,rem_chars);
15506  }
15507 
15509  {
15510  return details::conv_to_lcase_impl(s);
15511  }
15512 
15514  {
15515  return details::conv_to_ucase_impl(s);
15516  }
15517 
15518  inline details::fill_array_impl fill_array(unsigned char* data, const std::size_t& size)
15519  {
15520  return details::fill_array_impl(data,size);
15521  }
15522 
15523  inline details::fill_array_impl fill_array(char* data, const std::size_t& size)
15524  {
15525  return details::fill_array_impl(reinterpret_cast<unsigned char*>(data),size);
15526  }
15527 
15528  template <std::size_t N>
15529  inline details::fill_array_impl fill_array(unsigned char (&data)[N])
15530  {
15531  return details::fill_array_impl(data,N);
15532  }
15533 
15534  template <std::size_t N>
15535  inline details::fill_array_impl fill_array(char (&data)[N])
15536  {
15537  return details::fill_array_impl(reinterpret_cast<unsigned char*>(data),N);
15538  }
15539 
15540  inline details::fill_array_impl fill_array(std::string& data, const std::size_t& size)
15541  {
15542  return fill_array(const_cast<char*>(data.data()),size);
15543  }
15544 
15546  {
15547  return fill_array(const_cast<char*>(data.data()),data.size());
15548  }
15549 
15550  namespace details
15551  {
15552  static const unsigned char digit_table[] =
15553  {
15554  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0xFF - 0x07
15555  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x08 - 0x0F
15556  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x10 - 0x17
15557  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x18 - 0x1F
15558  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x20 - 0x27
15559  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x28 - 0x2F
15560  0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, // 0x30 - 0x37
15561  0x08, 0x09, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x38 - 0x3F
15562  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x40 - 0x47
15563  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x48 - 0x4F
15564  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x50 - 0x57
15565  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x58 - 0x5F
15566  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x60 - 0x67
15567  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x68 - 0x6F
15568  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x70 - 0x77
15569  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x78 - 0x7F
15570  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x80 - 0x87
15571  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x88 - 0x8F
15572  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x90 - 0x97
15573  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x98 - 0x9F
15574  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0xA0 - 0xA7
15575  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0xA8 - 0xAF
15576  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0xB0 - 0xB7
15577  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0xB8 - 0xBF
15578  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0xC0 - 0xC7
15579  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0xC8 - 0xCF
15580  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0xD0 - 0xD7
15581  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0xD8 - 0xDF
15582  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0xE0 - 0xE7
15583  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0xE8 - 0xEF
15584  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0xF0 - 0xF7
15585  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF // 0xF8 - 0xFF
15586  };
15587 
15588  static const std::size_t digit_table_size = sizeof(digit_table) / sizeof(unsigned char);
15589 
15590  template <typename T>
15591  static inline bool is_invalid_digit(const T& t)
15592  {
15593  static const unsigned int invalid_digit = 0xFF;
15594  return (static_cast<T>(invalid_digit) == t);
15595  }
15596 
15597  template <typename T>
15598  static inline bool is_valid_digit(const T& t)
15599  {
15600  static const unsigned int invalid_digit = 0xFF;
15601  return (static_cast<T>(invalid_digit) != t);
15602  }
15603 
15604  static const unsigned char digitr[] =
15605  {
15606  "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
15607  };
15608 
15609  static const unsigned char rev_3digit_lut[] =
15610  {
15611  "000100200300400500600700800900010110210310410510610710810910020120220320420"
15612  "520620720820920030130230330430530630730830930040140240340440540640740840940"
15613  "050150250350450550650750850950060160260360460560660760860960070170270370470"
15614  "570670770870970080180280380480580680780880980090190290390490590690790890990"
15615  "001101201301401501601701801901011111211311411511611711811911021121221321421"
15616  "521621721821921031131231331431531631731831931041141241341441541641741841941"
15617  "051151251351451551651751851951061161261361461561661761861961071171271371471"
15618  "571671771871971081181281381481581681781881981091191291391491591691791891991"
15619  "002102202302402502602702802902012112212312412512612712812912022122222322422"
15620  "522622722822922032132232332432532632732832932042142242342442542642742842942"
15621  "052152252352452552652752852952062162262362462562662762862962072172272372472"
15622  "572672772872972082182282382482582682782882982092192292392492592692792892992"
15623  "003103203303403503603703803903013113213313413513613713813913023123223323423"
15624  "523623723823923033133233333433533633733833933043143243343443543643743843943"
15625  "053153253353453553653753853953063163263363463563663763863963073173273373473"
15626  "573673773873973083183283383483583683783883983093193293393493593693793893993"
15627  "004104204304404504604704804904014114214314414514614714814914024124224324424"
15628  "524624724824924034134234334434534634734834934044144244344444544644744844944"
15629  "054154254354454554654754854954064164264364464564664764864964074174274374474"
15630  "574674774874974084184284384484584684784884984094194294394494594694794894994"
15631  "005105205305405505605705805905015115215315415515615715815915025125225325425"
15632  "525625725825925035135235335435535635735835935045145245345445545645745845945"
15633  "055155255355455555655755855955065165265365465565665765865965075175275375475"
15634  "575675775875975085185285385485585685785885985095195295395495595695795895995"
15635  "006106206306406506606706806906016116216316416516616716816916026126226326426"
15636  "526626726826926036136236336436536636736836936046146246346446546646746846946"
15637  "056156256356456556656756856956066166266366466566666766866966076176276376476"
15638  "576676776876976086186286386486586686786886986096196296396496596696796896996"
15639  "007107207307407507607707807907017117217317417517617717817917027127227327427"
15640  "527627727827927037137237337437537637737837937047147247347447547647747847947"
15641  "057157257357457557657757857957067167267367467567667767867967077177277377477"
15642  "577677777877977087187287387487587687787887987097197297397497597697797897997"
15643  "008108208308408508608708808908018118218318418518618718818918028128228328428"
15644  "528628728828928038138238338438538638738838938048148248348448548648748848948"
15645  "058158258358458558658758858958068168268368468568668768868968078178278378478"
15646  "578678778878978088188288388488588688788888988098198298398498598698798898998"
15647  "009109209309409509609709809909019119219319419519619719819919029129229329429"
15648  "529629729829929039139239339439539639739839939049149249349449549649749849949"
15649  "059159259359459559659759859959069169269369469569669769869969079179279379479"
15650  "579679779879979089189289389489589689789889989099199299399499599699799899999"
15651  };
15652 
15653  static const unsigned char rev_2digit_lut[] =
15654  {
15655  "0010203040506070809001112131415161718191"
15656  "0212223242526272829203132333435363738393"
15657  "0414243444546474849405152535455565758595"
15658  "0616263646566676869607172737475767778797"
15659  "0818283848586878889809192939495969798999"
15660  };
15661 
15662  #define strtk_register_pod_type(T)\
15663  template<> struct is_pod<T>{ typedef yes_t result_t; enum {result = true }; };\
15664  template<> struct is_pod<const T>{ typedef yes_t result_t; enum {result = true }; };\
15665  template<> struct is_pod<volatile T>{ typedef yes_t result_t; enum {result = true }; };\
15666  template<> struct is_pod<const volatile T>{ typedef yes_t result_t; enum {result = true }; };\
15667 
15669  strtk_register_pod_type(signed char)
15673  strtk_register_pod_type(long int)
15674  strtk_register_pod_type(long long int)
15675  strtk_register_pod_type(unsigned char)
15676  strtk_register_pod_type(unsigned short)
15677  strtk_register_pod_type(unsigned int)
15678  strtk_register_pod_type(unsigned long int)
15679  strtk_register_pod_type(unsigned long long int)
15681  strtk_register_pod_type(double)
15682  strtk_register_pod_type(long double)
15683 
15684  #undef strtk_register_pod_type
15685 
15686  template <typename>
15687  struct numeric { enum { length = 0, size = 32, bound_length = 0, min_exp = 0, max_exp = 0 }; };
15688 
15689  template<> struct numeric<short> { enum { length = 5, size = 16, bound_length = 4}; };
15690  template<> struct numeric<unsigned short> { enum { length = 5, size = 16, bound_length = 4}; };
15691 
15692  template<> struct numeric<int> { enum { length = 10, size = 16, bound_length = 9}; };
15693  template<> struct numeric<unsigned int> { enum { length = 10, size = 16, bound_length = 9}; };
15694 
15695  template<> struct numeric<long> { enum { length = 10, size = 16, bound_length = 9}; };
15696  template<> struct numeric<unsigned long> { enum { length = 10, size = 16, bound_length = 9}; };
15697 
15698  template<> struct numeric<long long> { enum { length = 19, size = 24, bound_length = 18}; };
15699  template<> struct numeric<unsigned long long int> { enum { length = 20, size = 24, bound_length = 19}; };
15700 
15701  template<> struct numeric<float> { enum { min_exp = -38, max_exp = +38, precision = 10}; };
15702  template<> struct numeric<double> { enum { min_exp = -308, max_exp = +308, precision = 15}; };
15703  template<> struct numeric<long double> { enum { min_exp = -308, max_exp = +308, precision = 15}; };
15704 
15705  #define strtk_register_unsigned_type_tag(T)\
15706  template<> struct supported_conversion_to_type<T> { typedef unsigned_type_tag type; };\
15707  template<> struct supported_conversion_from_type<T> { typedef unsigned_type_tag type; };
15708 
15709  #define strtk_register_signed_type_tag(T)\
15710  template<> struct supported_conversion_to_type<T>{ typedef signed_type_tag type; };\
15711  template<> struct supported_conversion_from_type<T> { typedef signed_type_tag type; };
15712 
15713  #define strtk_register_real_type_tag(T)\
15714  template<> struct supported_conversion_to_type<T>{ typedef real_type_tag type; };
15715 
15716  #define strtk_register_byte_type_tag(T)\
15717  template<> struct supported_conversion_to_type<T>{ typedef byte_type_tag type; };\
15718  template<> struct supported_conversion_from_type<T> { typedef byte_type_tag type; };
15719 
15720  #define strtk_register_hex_number_type_tag(T)\
15721  template<> struct supported_conversion_to_type<T >{ typedef hex_number_type_tag type; };
15722 
15724 
15725  #define strtk_register_base64_type_tag(T)\
15726  template<> struct supported_conversion_to_type<T >{ typedef base64_type_tag type; };
15727 
15728  #define strtk_register_supported_iterator_type(T)\
15729  template<> struct supported_iterator_type<T> { enum { value = true }; };
15730 
15731  template<> struct supported_conversion_to_type<bool> { typedef bool_type_tag type; };
15732  template<> struct supported_iterator_type<bool> { enum { value = true }; };
15733 
15734  template<> struct supported_conversion_to_type<std::string> { typedef stdstring_type_tag type; };
15735  template<> struct supported_iterator_type<std::string> { enum { value = true }; };
15736 
15737  template<> struct supported_conversion_to_type<strtk::util::value> { typedef value_type_tag type; };
15738  template<> struct supported_conversion_from_type<strtk::util::value> { typedef value_type_tag type; };
15739  template<> struct supported_iterator_type<strtk::util::value> { enum { value = true }; };
15740 
15742  template<> struct supported_iterator_type<strtk::details::expect_impl> { enum { value = true }; };
15743 
15745  template<> struct supported_iterator_type<strtk::details::iexpect_impl> { enum { value = true }; };
15746 
15747  template<> struct supported_conversion_to_type<strtk::details::like_impl> { typedef like_type_tag type; };
15748  template<> struct supported_iterator_type<strtk::details::like_impl> { enum { value = true }; };
15749 
15751  template<> struct supported_iterator_type<strtk::details::fill_array_impl> { enum { value = true }; };
15752 
15754  template<> struct supported_iterator_type<strtk::details::conv_to_lcase_impl> { enum { value = true }; };
15755 
15757  template<> struct supported_iterator_type<strtk::details::conv_to_ucase_impl> { enum { value = true }; };
15758 
15759  #define strtk_register_inrange_type_tag(T)\
15760  template<> struct supported_conversion_to_type<strtk::details::inrange_impl<T> > { typedef inrange_type_tag type; };\
15761  template<> struct supported_iterator_type<strtk::details::inrange_impl<T> > { enum { value = true }; };\
15762 
15763  #define strtk_register_trim_type_tag(T)\
15764  template<> struct supported_conversion_to_type<strtk::details::trim_impl<T> > { typedef trim_type_tag type; };\
15765  template<> struct supported_iterator_type<strtk::details::trim_impl<T> > { enum { value = true }; };
15766 
15767  #define strtk_register_stdstring_range_type_tag(T)\
15768  template<> struct supported_conversion_to_type< std::pair<T,T> >{ typedef stdstring_range_type_tag type; };
15769 
15770  #define strtk_register_sink_type_tag(T)\
15771  template<> struct supported_conversion_to_type<sink_type<std::vector<T> > > { typedef sink_type_tag type; };\
15772  template<> struct supported_conversion_to_type<sink_type<std::deque<T> > > { typedef sink_type_tag type; };\
15773  template<> struct supported_conversion_to_type<sink_type<std::list<T> > > { typedef sink_type_tag type; };\
15774  template<> struct supported_conversion_to_type<sink_type<std::set<T> > > { typedef sink_type_tag type; };\
15775  template<> struct supported_conversion_to_type<sink_type<std::multiset<T> > > { typedef sink_type_tag type; };\
15776  template<> struct supported_conversion_to_type<sink_type<std::queue<T> > > { typedef sink_type_tag type; };\
15777  template<> struct supported_conversion_to_type<sink_type<std::stack<T> > > { typedef sink_type_tag type; };\
15778  template<> struct supported_conversion_to_type<sink_type<std::priority_queue<T> > > { typedef sink_type_tag type; };\
15779  template<> struct supported_conversion_from_type<sink_type<std::vector<T> > > { typedef sink_type_tag type; };\
15780  template<> struct supported_conversion_from_type<sink_type<std::deque<T> > > { typedef sink_type_tag type; };\
15781  template<> struct supported_conversion_from_type<sink_type<std::list<T> > > { typedef sink_type_tag type; };\
15782  template<> struct supported_conversion_from_type<sink_type<std::set<T> > > { typedef sink_type_tag type; };\
15783  template<> struct supported_conversion_from_type<sink_type<std::multiset<T> > > { typedef sink_type_tag type; };\
15784  template<> struct supported_conversion_from_type<sink_type<std::queue<T> > > { typedef sink_type_tag type; };\
15785  template<> struct supported_conversion_from_type<sink_type<std::stack<T> > > { typedef sink_type_tag type; };\
15786  template<> struct supported_conversion_from_type<sink_type<std::priority_queue<T> > > { typedef sink_type_tag type; };\
15787 
15788  #define strtk_register_stl_container_to_string_conv_type_tag(T)\
15789  template<> struct supported_conversion_from_type<std::vector<T> > { typedef stl_seq_type_tag type; };\
15790  template<> struct supported_conversion_from_type<std::deque<T> > { typedef stl_seq_type_tag type; };\
15791  template<> struct supported_conversion_from_type<std::list<T> > { typedef stl_seq_type_tag type; };\
15792  template<> struct supported_conversion_from_type<std::set<T> > { typedef stl_seq_type_tag type; };\
15793  template<> struct supported_conversion_from_type<std::multiset<T> > { typedef stl_seq_type_tag type; };\
15794  template<> struct supported_conversion_from_type<std::queue<T> > { typedef stl_seq_type_tag type; };\
15795  template<> struct supported_conversion_from_type<std::stack<T> > { typedef stl_seq_type_tag type; };\
15796  template<> struct supported_conversion_from_type<std::priority_queue<T> > { typedef stl_seq_type_tag type; };\
15797 
15799 
15800  #define strtk_register_sequence_iterator_type(sequence)\
15801  strtk_register_supported_iterator_type(sequence<char>::iterator)\
15802  strtk_register_supported_iterator_type(sequence<char>::const_iterator)\
15803  strtk_register_supported_iterator_type(sequence<unsigned char>::iterator)\
15804  strtk_register_supported_iterator_type(sequence<unsigned char>::const_iterator)
15805 
15807  strtk_register_unsigned_type_tag(unsigned int)
15808  strtk_register_unsigned_type_tag(unsigned long)
15809  strtk_register_unsigned_type_tag(unsigned long long int)
15810 
15815 
15818  strtk_register_real_type_tag(long double)
15819 
15820  strtk_register_byte_type_tag(unsigned char)
15821  strtk_register_byte_type_tag(signed char)
15823 
15831 
15838  strtk_register_base64_type_tag(base64_to_number_sink<unsigned long long int>)
15839 
15840  strtk_register_stdstring_range_type_tag(std::string::iterator)
15841  strtk_register_stdstring_range_type_tag(std::string::const_iterator)
15846  strtk_register_stdstring_range_type_tag(const unsigned char*)
15847 
15852  strtk_register_supported_iterator_type(const signed char*)
15853  strtk_register_supported_iterator_type(const unsigned char*)
15854  strtk_register_supported_iterator_type(std::string::iterator)
15855  strtk_register_supported_iterator_type(std::string::const_iterator)
15856 
15859 
15862  strtk_register_sink_type_tag(long double)
15863  strtk_register_sink_type_tag(signed char)
15868  strtk_register_sink_type_tag(unsigned char)
15869  strtk_register_sink_type_tag(unsigned short)
15870  strtk_register_sink_type_tag(unsigned int)
15871  strtk_register_sink_type_tag(unsigned long)
15872  strtk_register_sink_type_tag(unsigned long long int)
15873  strtk_register_sink_type_tag(std::string)
15874 
15889 
15892  strtk_register_inrange_type_tag(long double)
15893  strtk_register_inrange_type_tag(signed char)
15898  strtk_register_inrange_type_tag(unsigned char)
15899  strtk_register_inrange_type_tag(unsigned short)
15900  strtk_register_inrange_type_tag(unsigned int)
15901  strtk_register_inrange_type_tag(unsigned long)
15902  strtk_register_inrange_type_tag(unsigned long long int)
15903  strtk_register_inrange_type_tag(std::string)
15904 
15907  strtk_register_trim_type_tag(long double)
15908  strtk_register_trim_type_tag(signed char)
15913  strtk_register_trim_type_tag(unsigned char)
15914  strtk_register_trim_type_tag(unsigned short)
15915  strtk_register_trim_type_tag(unsigned int)
15916  strtk_register_trim_type_tag(unsigned long)
15917  strtk_register_trim_type_tag(unsigned long long int)
15918  strtk_register_trim_type_tag(std::string)
15919 
15920  #define strtk_register_userdef_type_sink(T)\
15921  namespace strtk { namespace details { strtk_register_sink_type_tag(T) }}
15922 
15923  #undef strtk_register_unsigned_type_tag
15924  #undef strtk_register_signed_type_tag
15925  #undef strtk_register_real_type_tag
15926  #undef strtk_register_byte_type_tag
15927  #undef strtk_register_hex_number_type_tag
15928  #undef strtk_register_base64_type_tag
15929  #undef strtk_register_supported_iterator_type
15930  #undef strtk_register_stdstring_range_type_tag
15931  #undef strtk_register_sequence_iterator_type
15932  #undef strtk_register_stl_container_to_string_conv_type_tag
15933  #undef strtk_register_inrange_type_tag
15934  #undef strtk_register_trim_type_tag
15935 
15936  template <typename T>
15937  struct precision
15938  { static void set(std::iostream&) {} };
15939 
15940  #define strtk_register_iostream_precision(T)\
15941  template<> struct precision<T> { static void set(std::iostream& s, const std::streamsize& p = 10) { s.precision(p);} };
15942 
15946 
15947  #undef strtk_register_iostream_precision
15948 
15949  template <typename Iterator, typename T, typename Tag>
15950  inline bool string_to_type_converter_impl(Iterator& begin, const Iterator end, T& t, not_supported_type_tag)
15951  {
15952  #ifdef strtk_enable_lexical_cast
15953  try
15954  {
15955  t = boost::lexical_cast<T>(std::string(begin,end));
15956  }
15957  catch (const boost::bad_lexical_cast&)
15958  {
15959  return false;
15960  }
15961  begin = end;
15962  return true;
15963  #else
15964  try
15965  {
15966  std::stringstream ss(std::string(begin,end));
15967  ss >> t;
15968  }
15969  catch (const std::exception&)
15970  {
15971  return false;
15972  }
15973  begin = end;
15974  return true;
15975  #endif
15976  }
15977 
15978  template <typename Iterator>
15979  inline bool string_to_type_converter_impl(Iterator& begin, const Iterator end, strtk::util::value& v, value_type_tag)
15980  {
15981  return v(begin,end);
15982  }
15983 
15984  template <typename Iterator>
15985  inline bool string_to_type_converter_impl(Iterator& begin, const Iterator end, std::string& t, stdstring_type_tag)
15986  {
15987  t.assign(begin,end);
15988  begin = end;
15989  return true;
15990  }
15991 
15992  template <typename Iterator, typename Expect>
15993  inline bool string_to_type_converter_impl(Iterator& itr, const Iterator end, Expect& t, expect_type_tag)
15994  {
15995  if (!t(itr,end))
15996  return false;
15997  itr = end;
15998  return true;
15999  }
16000 
16001  template <typename Iterator, typename Like>
16002  inline bool string_to_type_converter_impl(Iterator& itr, const Iterator end, Like& t, like_type_tag)
16003  {
16004  if (!t(itr,end))
16005  return false;
16006  itr = end;
16007  return true;
16008  }
16009 
16010  template <typename Iterator, typename InRange>
16011  inline bool string_to_type_converter_impl(Iterator& itr, const Iterator end, InRange& t, inrange_type_tag)
16012  {
16013  if (!t(itr,end))
16014  return false;
16015  itr = end;
16016  return true;
16017  }
16018 
16019  template <typename Iterator, typename TrimToken>
16020  inline bool string_to_type_converter_impl(Iterator& itr, const Iterator end, TrimToken& t, trim_type_tag)
16021  {
16022  if (!t(itr,end))
16023  return false;
16024  itr = end;
16025  return true;
16026  }
16027 
16028  template <typename Iterator, typename CaseToken>
16029  inline bool string_to_type_converter_impl(Iterator& itr, const Iterator end, CaseToken& t, lcase_type_tag)
16030  {
16031  if (!t(itr,end))
16032  return false;
16033  itr = end;
16034  return true;
16035  }
16036 
16037  template <typename Iterator, typename CaseToken>
16038  inline bool string_to_type_converter_impl(Iterator& itr, const Iterator end, CaseToken& t, ucase_type_tag)
16039  {
16040  if (!t(itr,end))
16041  return false;
16042  itr = end;
16043  return true;
16044  }
16045 
16046  template <typename Iterator, typename Array>
16047  inline bool string_to_type_converter_impl(Iterator& itr, const Iterator end, Array& t, fillchararray_type_tag)
16048  {
16049  if (!t(itr,end))
16050  return false;
16051  itr = end;
16052  return true;
16053  }
16054 
16055  template <typename Iterator, typename T>
16056  inline bool string_to_type_converter_impl(Iterator& itr_external, const Iterator end, T& result, unsigned_type_tag)
16057  {
16058  if (end == itr_external) return false;
16059 
16060  Iterator itr = itr_external;
16061 
16062  if ('+' == (*itr))
16063  ++itr;
16064 
16065  if (end == itr)
16066  return false;
16067 
16068  while ((end != itr) && ('0' == (*itr))) ++itr;
16069  const std::size_t length = std::distance(itr,end);
16070 
16071  if (length > numeric<T>::length)
16072  return false;
16073 
16074  static const std::size_t bound_length = numeric<T>::bound_length;
16075  T t = 0;
16076 
16077  if (0 != length)
16078  {
16079  std::size_t interim_length = std::min<std::size_t>(bound_length,length);
16080  const Iterator interim_end = itr + interim_length;
16081  unsigned int digit[8];
16082  T t0 = 0;
16083  T t1 = 0;
16084  T t2 = 0;
16085  T t3 = 0;
16086 
16087  //Needed for incompetent and broken msvc compiler versions
16088  #ifdef _MSC_VER
16089  #pragma warning(push)
16090  #pragma warning(disable: 4127)
16091  #endif
16092 
16093  while (interim_length > 7)
16094  {
16095  if (((digit[0] = (itr[0] - '0')) > 9) ||
16096  ((digit[1] = (itr[1] - '0')) > 9) ||
16097  ((digit[2] = (itr[2] - '0')) > 9) ||
16098  ((digit[3] = (itr[3] - '0')) > 9) ||
16099  ((digit[4] = (itr[4] - '0')) > 9) ||
16100  ((digit[5] = (itr[5] - '0')) > 9) ||
16101  ((digit[6] = (itr[6] - '0')) > 9) ||
16102  ((digit[7] = (itr[7] - '0')) > 9))
16103  return false;
16104  else
16105  {
16106  t0 = static_cast<T>(digit[0] * 10000000 + digit[1] * 1000000);
16107  t1 = static_cast<T>(digit[2] * 100000 + digit[3] * 10000);
16108  t2 = static_cast<T>(digit[4] * 1000 + digit[5] * 100);
16109  t3 = static_cast<T>(digit[6] * 10 + digit[7] );
16110  t = t0 + t1 + t2 + t3 + static_cast<T>(t * 100000000);
16111  itr += 8;
16112  interim_length -= 8;
16113  }
16114  }
16115 
16116  while (interim_length > 3)
16117  {
16118  if (((digit[0] = (itr[0] - '0')) > 9) ||
16119  ((digit[1] = (itr[1] - '0')) > 9) ||
16120  ((digit[2] = (itr[2] - '0')) > 9) ||
16121  ((digit[3] = (itr[3] - '0')) > 9))
16122  return false;
16123  else
16124  {
16125  t1 = static_cast<T>(digit[0] * 1000 + digit[1] * 100);
16126  t2 = static_cast<T>(digit[2] * 10 + digit[3] );
16127  t3 = static_cast<T>(t * 10000 );
16128  t = t1 + t2 + t3;
16129  itr += 4;
16130  interim_length -= 4;
16131  }
16132  }
16133 
16134  while (interim_length > 1)
16135  {
16136  if (((digit[0] = (itr[0] - '0')) > 9) ||
16137  ((digit[1] = (itr[1] - '0')) > 9))
16138  return false;
16139  else
16140  {
16141  t1 = static_cast<T>(digit[0] * 10 + digit[1]);
16142  t2 = static_cast<T>(t * 100 );
16143  t = t1 + t2;
16144  itr += 2;
16145  interim_length -= 2;
16146  }
16147  }
16148 
16149  //Needed for incompetent and broken msvc compiler versions.
16150  #ifdef _MSC_VER
16151  #pragma warning(pop)
16152  #endif
16153 
16154  if (interim_length)
16155  {
16156  if ((digit[0] = (itr[0] - '0')) < 10)
16157  {
16158  t = static_cast<T>(digit[0] + t * 10);
16159  ++itr;
16160  }
16161  else
16162  return false;
16163  }
16164 
16165  if (interim_end != end)
16166  {
16167  if (1 == std::distance(interim_end,end))
16168  {
16169  typedef unsigned long long int num_type;
16170  static const num_type max = static_cast<num_type>(std::numeric_limits<T>::max());
16171  static const num_type penultimate_bound = static_cast<num_type>(max / 10);
16172  static const num_type final_digit = static_cast<num_type>(max % 10);
16173 
16174  digit[0] = static_cast<unsigned int>(*itr - '0');
16175  if (digit[0] <= 9)
16176  {
16177  if (t > penultimate_bound)
16178  return false;
16179  else if ((penultimate_bound == t) && (final_digit < digit[0]))
16180  return false;
16181  t = static_cast<T>(digit[0] + t * 10);
16182  }
16183  else
16184  return false;
16185  }
16186  else
16187  return false;
16188  }
16189  }
16190 
16191  result = static_cast<T>(t);
16192  return true;
16193  }
16194 
16195  template <typename Iterator, typename T>
16196  inline bool string_to_type_converter_impl(Iterator& itr_external, const Iterator end, T& result, signed_type_tag)
16197  {
16198  if (end == itr_external) return false;
16199 
16200  Iterator itr = itr_external;
16201 
16202  bool negative = false;
16203 
16204  if ('+' == (*itr))
16205  ++itr;
16206  else if ('-' == (*itr))
16207  {
16208  ++itr;
16209  negative = true;
16210  }
16211 
16212  if (end == itr) return false;
16213 
16214  while ((end != itr) && ('0' == (*itr))) ++itr;
16215 
16216  const std::size_t length = std::distance(itr,end);
16217 
16218  if (length > numeric<T>::length)
16219  return false;
16220 
16221  static const std::size_t bound_length = numeric<T>::bound_length;
16222  T t = 0;
16223 
16224  if (0 != length)
16225  {
16226  std::size_t interim_length = std::min<std::size_t>(bound_length,length);
16227  const Iterator interim_end = itr + interim_length;
16228  unsigned int digit[8];
16229  T t0 = 0;
16230  T t1 = 0;
16231  T t2 = 0;
16232  T t3 = 0;
16233 
16234  //Needed for incompetent and broken msvc compiler versions
16235  #ifdef _MSC_VER
16236  #pragma warning(push)
16237  #pragma warning(disable: 4127)
16238  #endif
16239 
16240  while (interim_length > 7)
16241  {
16242  if (((digit[0] = (itr[0] - '0')) > 9) ||
16243  ((digit[1] = (itr[1] - '0')) > 9) ||
16244  ((digit[2] = (itr[2] - '0')) > 9) ||
16245  ((digit[3] = (itr[3] - '0')) > 9) ||
16246  ((digit[4] = (itr[4] - '0')) > 9) ||
16247  ((digit[5] = (itr[5] - '0')) > 9) ||
16248  ((digit[6] = (itr[6] - '0')) > 9) ||
16249  ((digit[7] = (itr[7] - '0')) > 9) )
16250  return false;
16251  else
16252  {
16253  t0 = static_cast<T>(digit[0] * 10000000 + digit[1] * 1000000);
16254  t1 = static_cast<T>(digit[2] * 100000 + digit[3] * 10000);
16255  t2 = static_cast<T>(digit[4] * 1000 + digit[5] * 100);
16256  t3 = static_cast<T>(digit[6] * 10 + digit[7] );
16257  t = t0 + t1 + t2 + t3 + static_cast<T>(t * 100000000);
16258  itr += 8;
16259  interim_length -= 8;
16260  }
16261  }
16262 
16263  while (interim_length > 3)
16264  {
16265  if (((digit[0] = (itr[0] - '0')) > 9) ||
16266  ((digit[1] = (itr[1] - '0')) > 9) ||
16267  ((digit[2] = (itr[2] - '0')) > 9) ||
16268  ((digit[3] = (itr[3] - '0')) > 9) )
16269  return false;
16270  else
16271  {
16272  t0 = static_cast<T>(digit[0] * 1000 + digit[1] * 100);
16273  t1 = static_cast<T>(digit[2] * 10 + digit[3] );
16274  t = t0 + t1 + static_cast<T>(t * 10000);
16275  itr += 4;
16276  interim_length -= 4;
16277  }
16278  }
16279 
16280  while (interim_length > 2)
16281  {
16282  if (((digit[0] = (itr[0] - '0')) > 9) ||
16283  ((digit[1] = (itr[1] - '0')) > 9) ||
16284  ((digit[2] = (itr[2] - '0')) > 9))
16285  return false;
16286  else
16287  {
16288  t0 = static_cast<T>(digit[0] * 100 + digit[1] * 10);
16289  t1 = static_cast<T>(t * 1000 + digit[2] );
16290  t = t0 + t1;
16291  itr += 3;
16292  interim_length -= 3;
16293  }
16294  }
16295 
16296  while (interim_length > 1)
16297  {
16298  if (((digit[0] = (itr[0] - '0')) > 9) ||
16299  ((digit[1] = (itr[1] - '0')) > 9))
16300  return false;
16301  else
16302  {
16303  t0 = static_cast<T>(digit[0] * 10 + digit[1]);
16304  t = t0 + static_cast<T>(t * 100);
16305  itr += 2;
16306  interim_length -= 2;
16307  }
16308  }
16309 
16310  //Needed for incompetent and broken msvc compiler versions.
16311  #ifdef _MSC_VER
16312  #pragma warning(pop)
16313  #endif
16314 
16315  if (interim_length)
16316  {
16317  if ((digit[0] = (itr[0] - '0')) < 10)
16318  {
16319  t = static_cast<T>(digit[0] + t * 10);
16320  ++itr;
16321  }
16322  else
16323  return false;
16324  }
16325 
16326  if (interim_end != end)
16327  {
16328  if (1 == std::distance(interim_end,end))
16329  {
16330  typedef unsigned long long int num_type;
16331  static const num_type max = static_cast<num_type>(std::numeric_limits<T>::max());
16332  static const num_type min = static_cast<num_type>(static_cast<long long>(-1) * std::numeric_limits<T>::min());
16333  static const num_type positive_penultimate_bound = static_cast<num_type>(max / 10);
16334  static const num_type negative_penultimate_bound = static_cast<num_type>(min / 10);
16335  static const num_type positive_final_digit = static_cast<num_type>(max % 10);
16336  static const num_type negative_final_digit = static_cast<num_type>(min % 10);
16337 
16338  digit[0] = static_cast<unsigned int>(*itr - '0');
16339 
16340  if (digit[0] < 10)
16341  {
16342  if (negative)
16343  {
16344  if (static_cast<num_type>(t) > negative_penultimate_bound)
16345  return false;
16346  else if (
16347  (negative_penultimate_bound == static_cast<num_type>(t)) &&
16348  (negative_final_digit < digit[0])
16349  )
16350  return false;
16351  }
16352  else
16353  {
16354  if (static_cast<num_type>(t) > positive_penultimate_bound)
16355  return false;
16356  else if (
16357  (positive_penultimate_bound == static_cast<num_type>(t)) &&
16358  (positive_final_digit < digit[0])
16359  )
16360  return false;
16361  }
16362  t = static_cast<T>(digit[0] + t * 10);
16363  }
16364  else
16365  return false;
16366  }
16367  else
16368  return false;
16369  }
16370  }
16371  itr_external = itr;
16372  result = static_cast<T>((negative) ? -t : t);
16373  return true;
16374  }
16375 
16376  template <typename Iterator, typename T>
16377  inline bool string_to_type_converter_impl_ref(Iterator& itr, const Iterator end, T& result, signed_type_tag)
16378  {
16379  if (end == itr) return false;
16380 
16381  T t = 0;
16382  bool negative = false;
16383 
16384  if ('+' == (*itr))
16385  ++itr;
16386  else if ('-' == (*itr))
16387  {
16388  ++itr;
16389  negative = true;
16390  }
16391 
16392  if (end == itr)
16393  return false;
16394 
16395  unsigned int digit_count = 0;
16396  while ((end != itr) && ('0' == (*itr))) ++itr;
16397 
16398  bool return_result = true;
16399  while (end != itr)
16400  {
16401  const unsigned char digit = (*itr - '0');
16402  if (digit > 9)
16403  {
16404  return_result = false;
16405  break;
16406  }
16407 
16408  if ((++digit_count) <= numeric<T>::bound_length)
16409  {
16410  t *= 10;
16411  t += digit;
16412  }
16413  else
16414  {
16415  typedef unsigned long long int base_type;
16416  static const base_type max_limit = +std::numeric_limits<T>::max();
16417  static const base_type min_limit = -std::numeric_limits<T>::min();
16418  base_type tmp = static_cast<base_type>(t) * 10 + digit;
16419  if (negative && static_cast<base_type>(tmp) > min_limit)
16420  return_result = false;
16421  else if (static_cast<base_type>(tmp) > max_limit)
16422  return_result = false;
16423  t = static_cast<T>(tmp);
16424  }
16425  ++itr;
16426  }
16427 
16428  result = static_cast<T>((negative) ? -t : t);
16429  return return_result;
16430  }
16431 
16432  template <typename Iterator, typename T>
16433  inline bool parse_nan(Iterator& itr, const Iterator end, T& t)
16434  {
16435  typedef typename std::iterator_traits<Iterator>::value_type type;
16436  static const std::size_t nan_length = 3;
16437  if (std::distance(itr,end) != static_cast<int>(nan_length))
16438  return false;
16439  if (static_cast<type>('n') == (*itr))
16440  {
16441  if ((static_cast<type>('a') != *(itr + 1)) || (static_cast<type>('n') != *(itr + 2)))
16442  {
16443  return false;
16444  }
16445  }
16446  else if ((static_cast<type>('A') != *(itr + 1)) || (static_cast<type>('N') != *(itr + 2)))
16447  {
16448  return false;
16449  }
16450  t = std::numeric_limits<T>::quiet_NaN();
16451  return true;
16452  }
16453 
16454  template <typename Iterator, typename T>
16455  inline bool parse_inf(Iterator& itr, const Iterator end, T& t, bool negative)
16456  {
16457  static const char inf_uc[] = "INFINITY";
16458  static const char inf_lc[] = "infinity";
16459  static const std::size_t inf_length = 8;
16460  const std::size_t length = std::distance(itr,end);
16461  if ((3 != length) && (inf_length != length))
16462  return false;
16463  const char* inf_itr = ('i' == (*itr)) ? inf_lc : inf_uc;
16464  while (end != itr)
16465  {
16466  if (*inf_itr == static_cast<char>(*itr))
16467  {
16468  ++itr;
16469  ++inf_itr;
16470  continue;
16471  }
16472  else
16473  return false;
16474  }
16475  if (negative)
16476  t = -std::numeric_limits<T>::infinity();
16477  else
16478  t = std::numeric_limits<T>::infinity();
16479  return true;
16480  }
16481 
16482  template <typename Iterator, typename T>
16483  inline bool string_to_type_converter_impl(Iterator& itr_external, const Iterator end, T& t, real_type_tag)
16484  {
16485  if (end == itr_external) return false;
16486  Iterator itr = itr_external;
16487  double d = 0.0;
16488  bool negative = false;
16489  if ('+' == (*itr))
16490  ++itr;
16491  else if ('-' == (*itr))
16492  {
16493  ++itr;
16494  negative = true;
16495  }
16496 
16497  if (end == itr)
16498  return false;
16499 
16500  if (('I' <= (*itr)) && ((*itr) <= 'n'))
16501  {
16502  if (('i' == (*itr)) || ('I' == (*itr)))
16503  {
16504  return parse_inf(itr,end,t,negative);
16505  }
16506  else if (('n' == (*itr)) || ('N' == (*itr)))
16507  {
16508  return parse_nan(itr,end,t);
16509  }
16510  else
16511  return false;
16512  }
16513 
16514  bool instate = false;
16515  int pre_decimal = 0;
16516 
16517  if ('.' != (*itr))
16518  {
16519  const Iterator curr = itr;
16520  while ((end != itr) && ('0' == (*itr))) ++itr;
16521  const Iterator post_zero_cull_itr = itr;
16522  unsigned char digit = 0;
16523 
16524  #define parse_digit_1 \
16525  if ((digit = static_cast<unsigned char>((*itr) - '0')) < 10) { d *= 10.0; d += digit; } else break; if (end == ++itr) break; \
16526 
16527  #define parse_digit_2 \
16528  if ((digit = static_cast<unsigned char>((*itr) - '0')) < 10) { d *= 10.0; d += digit; } else break; ++itr;\
16529 
16530  while (end != itr)
16531  {
16540  }
16541  #undef parse_digit_1
16542  #undef parse_digit_2
16543  if (curr != itr) instate = true;
16544  pre_decimal = static_cast<int>(std::distance(post_zero_cull_itr,itr));
16545  }
16546 
16547  int exponent = 0;
16548 
16549  if (end != itr)
16550  {
16551  if ('.' == (*itr))
16552  {
16553  ++itr;
16554  const Iterator curr = itr;
16555  unsigned char digit = 0;
16556 
16557  #define parse_digit_1 \
16558  if ((digit = static_cast<unsigned char>((*itr) - '0')) < 10) { d *= 10.0; d += digit; } else break; if (end == ++itr) break; \
16559 
16560  #define parse_digit_2 \
16561  if ((digit = static_cast<unsigned char>((*itr) - '0')) < 10) { d *= 10.0; d += digit; } else break; ++itr;\
16562 
16563  while (end != itr)
16564  {
16573  }
16574  #undef parse_digit_1
16575  #undef parse_digit_2
16576  if (curr != itr) instate = true;
16577  exponent -= static_cast<int>(std::distance(curr,itr));
16578  }
16579 
16580  if (end != itr)
16581  {
16582  typename std::iterator_traits<Iterator>::value_type c = (*itr);
16583 
16584  if (('e' == c) || ('E' == c))
16585  {
16586  ++itr;
16587  int exp = 0;
16589  {
16590  if (end == itr)
16591  return false;
16592  else
16593  c = (*itr);
16594  }
16595 
16596  if ((exp < numeric<T>::min_exp) || (numeric<T>::max_exp < exp))
16597  return false;
16598 
16599  exponent += exp;
16600  }
16601 
16602  if (('f' == c) || ('F' == c) || ('l' == c) || ('L' == c))
16603  ++itr;
16604  else if ('#' == c)
16605  {
16606  ++itr;
16607  if (end == itr)
16608  return false;
16609  if ((10.0 != d) || (exponent != -1))
16610  return false;
16611  if (('I' <= (*itr)) && ((*itr) <= 'n'))
16612  {
16613  if (('i' == (*itr)) || ('I' == (*itr)))
16614  {
16615  return parse_inf(itr,end,t,negative);
16616  }
16617  else if (('n' == (*itr)) || ('N' == (*itr)))
16618  {
16619  return parse_nan(itr,end,t);
16620  }
16621  else
16622  return false;
16623  }
16624  return false;
16625  }
16626  }
16627  }
16628 
16629  if ((end != itr) || (!instate))
16630  return false;
16631 
16632  if (0 != exponent)
16633  {
16634  if (
16635  (std::numeric_limits<T>::max_exponent10 < (exponent + pre_decimal)) ||
16636  (std::numeric_limits<T>::min_exponent10 > (exponent + pre_decimal))
16637  )
16638  {
16639  return false;
16640  }
16641 
16642  const int e = std::abs(exponent);
16643  static const double fract10[] =
16644  {
16645  0.0,
16646  1.0E+001, 1.0E+002, 1.0E+003, 1.0E+004, 1.0E+005, 1.0E+006, 1.0E+007, 1.0E+008, 1.0E+009, 1.0E+010,
16647  1.0E+011, 1.0E+012, 1.0E+013, 1.0E+014, 1.0E+015, 1.0E+016, 1.0E+017, 1.0E+018, 1.0E+019, 1.0E+020,
16648  1.0E+021, 1.0E+022, 1.0E+023, 1.0E+024, 1.0E+025, 1.0E+026, 1.0E+027, 1.0E+028, 1.0E+029, 1.0E+030,
16649  1.0E+031, 1.0E+032, 1.0E+033, 1.0E+034, 1.0E+035, 1.0E+036, 1.0E+037, 1.0E+038, 1.0E+039, 1.0E+040,
16650  1.0E+041, 1.0E+042, 1.0E+043, 1.0E+044, 1.0E+045, 1.0E+046, 1.0E+047, 1.0E+048, 1.0E+049, 1.0E+050,
16651  1.0E+051, 1.0E+052, 1.0E+053, 1.0E+054, 1.0E+055, 1.0E+056, 1.0E+057, 1.0E+058, 1.0E+059, 1.0E+060,
16652  1.0E+061, 1.0E+062, 1.0E+063, 1.0E+064, 1.0E+065, 1.0E+066, 1.0E+067, 1.0E+068, 1.0E+069, 1.0E+070,
16653  1.0E+071, 1.0E+072, 1.0E+073, 1.0E+074, 1.0E+075, 1.0E+076, 1.0E+077, 1.0E+078, 1.0E+079, 1.0E+080,
16654  1.0E+081, 1.0E+082, 1.0E+083, 1.0E+084, 1.0E+085, 1.0E+086, 1.0E+087, 1.0E+088, 1.0E+089, 1.0E+090,
16655  1.0E+091, 1.0E+092, 1.0E+093, 1.0E+094, 1.0E+095, 1.0E+096, 1.0E+097, 1.0E+098, 1.0E+099, 1.0E+100,
16656  1.0E+101, 1.0E+102, 1.0E+103, 1.0E+104, 1.0E+105, 1.0E+106, 1.0E+107, 1.0E+108, 1.0E+109, 1.0E+110,
16657  1.0E+111, 1.0E+112, 1.0E+113, 1.0E+114, 1.0E+115, 1.0E+116, 1.0E+117, 1.0E+118, 1.0E+119, 1.0E+120,
16658  1.0E+121, 1.0E+122, 1.0E+123, 1.0E+124, 1.0E+125, 1.0E+126, 1.0E+127, 1.0E+128, 1.0E+129, 1.0E+130,
16659  1.0E+131, 1.0E+132, 1.0E+133, 1.0E+134, 1.0E+135, 1.0E+136, 1.0E+137, 1.0E+138, 1.0E+139, 1.0E+140,
16660  1.0E+141, 1.0E+142, 1.0E+143, 1.0E+144, 1.0E+145, 1.0E+146, 1.0E+147, 1.0E+148, 1.0E+149, 1.0E+150,
16661  1.0E+151, 1.0E+152, 1.0E+153, 1.0E+154, 1.0E+155, 1.0E+156, 1.0E+157, 1.0E+158, 1.0E+159, 1.0E+160,
16662  1.0E+161, 1.0E+162, 1.0E+163, 1.0E+164, 1.0E+165, 1.0E+166, 1.0E+167, 1.0E+168, 1.0E+169, 1.0E+170,
16663  1.0E+171, 1.0E+172, 1.0E+173, 1.0E+174, 1.0E+175, 1.0E+176, 1.0E+177, 1.0E+178, 1.0E+179, 1.0E+180,
16664  1.0E+181, 1.0E+182, 1.0E+183, 1.0E+184, 1.0E+185, 1.0E+186, 1.0E+187, 1.0E+188, 1.0E+189, 1.0E+190,
16665  1.0E+191, 1.0E+192, 1.0E+193, 1.0E+194, 1.0E+195, 1.0E+196, 1.0E+197, 1.0E+198, 1.0E+199, 1.0E+200,
16666  1.0E+221, 1.0E+222, 1.0E+223, 1.0E+224, 1.0E+225, 1.0E+226, 1.0E+227, 1.0E+228, 1.0E+229, 1.0E+230,
16667  1.0E+231, 1.0E+232, 1.0E+233, 1.0E+234, 1.0E+235, 1.0E+236, 1.0E+237, 1.0E+238, 1.0E+239, 1.0E+240,
16668  1.0E+241, 1.0E+242, 1.0E+243, 1.0E+244, 1.0E+245, 1.0E+246, 1.0E+247, 1.0E+248, 1.0E+249, 1.0E+250,
16669  1.0E+251, 1.0E+252, 1.0E+253, 1.0E+254, 1.0E+255, 1.0E+256, 1.0E+257, 1.0E+258, 1.0E+259, 1.0E+260,
16670  1.0E+261, 1.0E+262, 1.0E+263, 1.0E+264, 1.0E+265, 1.0E+266, 1.0E+267, 1.0E+268, 1.0E+269, 1.0E+270,
16671  1.0E+271, 1.0E+272, 1.0E+273, 1.0E+274, 1.0E+275, 1.0E+276, 1.0E+277, 1.0E+278, 1.0E+279, 1.0E+280,
16672  1.0E+281, 1.0E+282, 1.0E+283, 1.0E+284, 1.0E+285, 1.0E+286, 1.0E+287, 1.0E+288, 1.0E+289, 1.0E+290,
16673  1.0E+291, 1.0E+292, 1.0E+293, 1.0E+294, 1.0E+295, 1.0E+296, 1.0E+297, 1.0E+298, 1.0E+299, 1.0E+300,
16674  1.0E+301, 1.0E+302, 1.0E+303, 1.0E+304, 1.0E+305, 1.0E+306, 1.0E+307, 1.0E+308
16675  };
16676 
16677  static const std::size_t fract10_size = sizeof(fract10) / sizeof(double);
16678 
16679  if (d != 0.0)
16680  {
16681  if (static_cast<std::size_t>(e) < fract10_size)
16682  {
16683  if (exponent > 0)
16684  d *= fract10[e];
16685  else
16686  d /= fract10[e];
16687  }
16688  else
16689  d *= std::pow(10.0, 1.0 * exponent);
16690  }
16691  }
16692 
16693  t = static_cast<T>((negative) ? -d : d);
16694  return true;
16695  }
16696 
16697  template <typename Iterator, typename T>
16698  inline bool string_to_type_converter_impl(Iterator& itr, const Iterator end, T& t, byte_type_tag)
16699  {
16700  if (1 != std::distance(itr,end))
16701  return false;
16702  t = static_cast<T>(*itr);
16703  itr = end;
16704  return true;
16705  }
16706 
16707  template <typename Iterator>
16708  inline bool string_to_type_converter_impl(Iterator& itr, const Iterator end, bool& t, bool_type_tag)
16709  {
16710  if (1 != std::distance(itr,end))
16711  return false;
16712  t = (('0' == (*itr)) ? false : true);
16713  itr = end;
16714  return true;
16715  }
16716 
16717  template <typename Iterator, typename IgnoreTokenType>
16718  inline bool string_to_type_converter_impl(Iterator& itr, const Iterator end, IgnoreTokenType&, ignore_token_type_tag)
16719  {
16720  itr = end;
16721  return true;
16722  }
16723 
16724  template <typename Iterator, typename HexSinkType>
16725  inline bool string_to_type_converter_impl(Iterator& itr, const Iterator end, HexSinkType& t, hex_number_type_tag)
16726  {
16727  t = std::pair<Iterator,Iterator>(itr,end);
16728  if (!t.valid())
16729  return false;
16730  itr = end;
16731  return true;
16732  }
16733 
16734  template <typename Iterator, typename HexSinkType>
16735  inline bool string_to_type_converter_impl(Iterator& itr, const Iterator end, HexSinkType& t, hex_string_type_tag)
16736  {
16737  t = std::pair<Iterator,Iterator>(itr,end);
16738  if (!t.valid())
16739  return false;
16740  itr = end;
16741  return true;
16742  }
16743 
16744  template <typename Iterator, typename Base64SinkType>
16745  inline bool string_to_type_converter_impl(Iterator& itr, const Iterator end, Base64SinkType& t, base64_type_tag)
16746  {
16747  t = std::pair<Iterator,Iterator>(itr,end);
16748  if (!t.valid())
16749  return false;
16750  itr = end;
16751  return true;
16752  }
16753 
16754  template <typename Iterator, typename SinkType>
16755  inline bool string_to_type_converter_impl(Iterator& itr, const Iterator end, SinkType& t, sink_type_tag)
16756  {
16757  if (!t.parse(itr,end))
16758  return false;
16759  itr = end;
16760  return true;
16761  }
16762 
16763  template <typename T>
16765  {
16766  #ifdef strtk_enable_lexical_cast
16767  try
16768  {
16769  s = boost::lexical_cast<std::string>(t);
16770  }
16771  catch (const boost::bad_lexical_cast&)
16772  {
16773  return false;
16774  }
16775  #else
16776  try
16777  {
16778  std::stringstream ss;
16779  precision<T>::set(ss);
16780  ss << t;
16781  s = ss.str();
16782  }
16783  catch (const std::exception&)
16784  {
16785  return false;
16786  }
16787  #endif
16788  return true;
16789  }
16790 
16791  template <typename T>
16793  {
16794  static const std::size_t radix = 10;
16795  static const std::size_t radix_sqr = radix * radix;
16796  static const std::size_t radix_cube = radix * radix * radix;
16797  unsigned char buffer[numeric<T>::size];
16798  unsigned char* itr = buffer + (numeric<T>::size - 1);
16799  T remainder = 0;
16800 
16801  if (0 != value)
16802  {
16803  std::size_t index = 0;
16804  T temp_v = 0;
16805  while (value >= static_cast<T>(radix_sqr))
16806  {
16807  temp_v = value / radix_cube;
16808  remainder = value - (temp_v * radix_cube);
16809  value = temp_v;
16810  index = static_cast<std::size_t>(remainder * 3);
16811  *(itr ) = details::rev_3digit_lut[index ];
16812  *(itr - 1) = details::rev_3digit_lut[index + 1];
16813  *(itr - 2) = details::rev_3digit_lut[index + 2];
16814  itr -= 3;
16815  }
16816 
16817  while (value >= static_cast<T>(radix))
16818  {
16819  temp_v = value / radix_sqr;
16820  remainder = value - (temp_v * radix_sqr);
16821  value = temp_v;
16822  index = static_cast<std::size_t>(remainder << 1);
16823  *(itr--) = details::rev_2digit_lut[index + 0];
16824  *(itr--) = details::rev_2digit_lut[index + 1];
16825  }
16826 
16827  if (0 != value)
16828  {
16829  *(itr--) = strtk::details::digitr[value];
16830  }
16831  }
16832  else
16833  *(itr--) = '0';
16834 
16835  itr++;
16836  result.assign(reinterpret_cast<char*>(itr), (buffer + numeric<T>::size) - itr);
16837  return true;
16838  }
16839 
16840  template <typename T>
16842  {
16843  static const std::size_t radix = 10;
16844  static const std::size_t radix_sqr = radix * radix;
16845  static const std::size_t radix_cube = radix * radix * radix;
16846  unsigned char buffer[strtk::details::numeric<T>::size];
16847  unsigned char* itr = buffer + (strtk::details::numeric<T>::size - 1);
16848  bool negative = (value < 0);
16849  if (negative)
16850  value = static_cast<T>(-1 * value);
16851  T remainder = 0;
16852 
16853  if (0 != value)
16854  {
16855  std::size_t index = 0;
16856  T temp_v = 0;
16857  while (value >= static_cast<T>(radix_sqr))
16858  {
16859  temp_v = value / radix_cube;
16860  remainder = value - (temp_v * radix_cube);
16861  value = temp_v;
16862  index = static_cast<std::size_t>(remainder * 3);
16863  *(itr ) = details::rev_3digit_lut[index ];
16864  *(itr - 1) = details::rev_3digit_lut[index + 1];
16865  *(itr - 2) = details::rev_3digit_lut[index + 2];
16866  itr -= 3;
16867  }
16868 
16869  while (value >= static_cast<T>(radix))
16870  {
16871  temp_v = value / radix_sqr;
16872  remainder = value - (temp_v * radix_sqr);
16873  value = temp_v;
16874  index = static_cast<std::size_t>(remainder) << 1;
16875  *(itr ) = details::rev_2digit_lut[index ];
16876  *(itr - 1) = details::rev_2digit_lut[index + 1];
16877  itr -= 2;
16878  }
16879 
16880  if (0 != value)
16881  {
16882  *(itr--) = strtk::details::digitr[value];
16883  }
16884  }
16885  else
16886  *(itr--) = '0';
16887 
16888  if (negative) *(itr--) = '-';
16889 
16890  itr++;
16891  result.assign(reinterpret_cast<char*>(itr), (buffer + numeric<T>::size) - itr);
16892  return true;
16893  }
16894 
16895  template <typename T>
16896  inline bool type_to_string_converter_impl(const T& value, std::string& result, byte_type_tag)
16897  {
16898  result.resize(1);
16899  result[0] = static_cast<char>(value);
16900  return true;
16901  }
16902 
16903  inline bool type_to_string_converter_impl(const bool& value, std::string& result, bool_type_tag)
16904  {
16905  result.resize(1);
16906  result[0] = value ? '1' : '0';
16907  return true;
16908  }
16909 
16911  {
16912  result = value;
16913  return true;
16914  }
16915 
16916  template <typename Iterator>
16917  inline bool type_to_string_converter_impl(const std::pair<Iterator,Iterator>& range, std::string& result, stdstring_range_type_tag)
16918  {
16919  result.assign(range.first,range.second);
16920  return true;
16921  }
16922 
16923  template <typename SinkType>
16925  {
16926  //Generic conversion not supported for sinks. Use joins or custom converters.
16927  return false;
16928  }
16929 
16930  template <typename STLContainerType>
16931  inline bool type_to_string_converter_impl(const STLContainerType&, std::string&, stl_seq_type_tag)
16932  {
16933  //Generic conversion not supported for stl containers. Use joins or custom converters.
16934  return false;
16935  }
16936 
16937  template <typename T>
16939  {
16940  static const std::string s("Unknown");
16941  return s;
16942  }
16943 
16944  #define strtk_register_type_name(Type)\
16945  template <> inline std::string type_name<Type>() { static const std::string s(#Type); return s; }
16946 
16948  strtk_register_type_name(unsigned char)
16952  strtk_register_type_name(long long)
16953  strtk_register_type_name(unsigned short)
16954  strtk_register_type_name(unsigned int)
16955  strtk_register_type_name(unsigned long)
16956  strtk_register_type_name(unsigned long long int)
16957  strtk_register_type_name(double)
16959  strtk_register_type_name(long double)
16960  strtk_register_type_name(std::string)
16961 
16962  #undef strtk_register_type_name
16963 
16964  template <typename T>
16965  inline std::string type_name(const T&)
16966  {
16967  static const std::string s = type_name<T>();
16968  return s;
16969  }
16970 
16971  template <typename T1, typename T2>
16972  inline std::string type_name(const std::pair<T1,T2>& p)
16973  {
16974  static const std::string s = std::string("std::pair<" +
16975  type_name(p.first) +
16976  "," +
16977  type_name(p.second) +
16978  ">");
16979  return s;
16980  }
16981 
16982  template <typename T>
16983  inline std::size_t type_length()
16984  {
16985  return numeric<T>::length;
16986  }
16987 
16988  template <typename T>
16989  inline std::size_t type_length(const T&)
16990  {
16991  return type_length<T>();
16992  }
16993 
16994  inline std::size_t type_length(const std::string& s)
16995  {
16996  return s.size();
16997  }
16998 
16999  template <typename T1, typename T2>
17000  inline std::size_t type_length(const std::pair<T1,T2>&)
17001  {
17002  return type_length<T1>() + type_length<T2>();
17003  }
17004 
17005  } // namespace details
17006 
17007  template <typename T>
17008  inline std::string type_name(const T& t)
17009  {
17010  static const std::string s = details::type_name<T>(t);
17011  return s;
17012  }
17013 
17014  template <typename T, std::size_t N>
17015  inline std::string type_name(const T(&)[N])
17016  {
17017  static const std::string s = details::type_name<T>() +
17018  std::string("[") + type_to_string(N) + std::string("]");
17019  return s;
17020  }
17021 
17022  template <typename T1, typename T2>
17023  inline std::string type_name(const std::pair<T1,T2>& p)
17024  {
17025  static const std::string s = std::string("std::pair<" +
17026  type_name(p.first) +
17027  "," +
17028  type_name(p.second) +
17029  ">");
17030  return s;
17031  }
17032 
17033  #define strtk_register_sequence_type_name(Type)\
17034  template <typename T, typename Allocator>\
17035  inline std::string type_name(const Type<T,Allocator>&)\
17036  {\
17037  static const std::string s = std::string(#Type) + std::string("<" + details::type_name<T>() + ">");\
17038  return s;\
17039  }
17040 
17041  #define strtk_register_set_type_name(Type)\
17042  template <typename T, typename Comparator, typename Allocator>\
17043  inline std::string type_name(const Type<T,Comparator,Allocator>&)\
17044  {\
17045  static const std::string s = std::string(#Type) + std::string("<" + details::type_name<T>() + ">");\
17046  return s;\
17047  }
17048 
17053  strtk_register_set_type_name(std::multiset)
17054 
17055  template <typename T>
17056  inline std::size_t type_length()
17057  {
17058  return details::type_length<T>();
17059  }
17060 
17061  template <typename T>
17062  inline std::size_t type_length(const T&)
17063  {
17064  return type_length<T>();
17065  }
17066 
17068  {
17069  public:
17070 
17071  explicit ext_string()
17072  {}
17073 
17074  explicit ext_string(const std::string& s)
17075  : s_(s)
17076  {}
17077 
17078  explicit ext_string(const char* s)
17079  : s_(s)
17080  {}
17081 
17083  : s_(r.begin(),r.end())
17084  {}
17085 
17087  : s_(es.s_)
17088  {}
17089 
17090  template <typename T>
17091  inline ext_string& operator << (const T& t)
17092  {
17093  s_ += type_to_string(t);
17094  return (*this);
17095  }
17096 
17097  inline operator std::string () const
17098  {
17099  return s_;
17100  }
17101 
17102  inline std::string clone() const
17103  {
17104  return s_;
17105  }
17106 
17107  inline const std::string& as_string() const
17108  {
17109  return s_;
17110  }
17111 
17113  {
17114  return s_;
17115  }
17116 
17117  template <typename T>
17118  inline T as_type() const
17119  {
17120  return string_to_type_converter<T>(s_);
17121  }
17122 
17123  template <typename T>
17124  inline bool as_type(T& t) const
17125  {
17126  return string_to_type_converter(s_,t);
17127  }
17128 
17129  inline bool imatch(const std::string& s) const
17130  {
17131  return strtk::imatch(s_,s);
17132  }
17133 
17134  inline bool imatch(const ext_string& es) const
17135  {
17136  return strtk::imatch(s_,es.s_);
17137  }
17138 
17140  {
17142  return (*this);
17143  }
17144 
17146  {
17148  return (*this);
17149  }
17150 
17151  template <typename Predicate>
17152  inline ext_string& remove_leading(const Predicate& p)
17153  {
17154  if (s_.empty()) return (*this);
17155  strtk::remove_leading(p,s_);
17156  return (*this);
17157  }
17158 
17159  inline ext_string& remove_leading(const std::string& removal_set)
17160  {
17161  if (removal_set.empty())
17162  return (*this);
17163  else if (1 == removal_set.size())
17165  else
17167  return (*this);
17168  }
17169 
17170  template <typename Predicate>
17171  inline ext_string& remove_trailing(const Predicate& p)
17172  {
17173  if (s_.empty()) return (*this);
17174  strtk::remove_trailing(p,s_);
17175  return (*this);
17176  }
17177 
17178  inline ext_string& remove_trailing(const std::string& removal_set)
17179  {
17180  if (removal_set.empty())
17181  return (*this);
17182  else if (1 == removal_set.size())
17184  else
17186  return (*this);
17187  }
17188 
17189  template <typename T>
17190  inline ext_string& operator += (const T& t)
17191  {
17192  s_.append(type_to_string(t));
17193  return (*this);
17194  }
17195 
17196  inline ext_string& operator -= (const std::string& pattern)
17197  {
17198  replace(pattern,"");
17199  return (*this);
17200  }
17201 
17202  inline ext_string& operator *= (const std::size_t& n)
17203  {
17205  return (*this);
17206  }
17207 
17208  inline void replace(const std::string& pattern, const std::string& replace_pattern)
17209  {
17210  std::string result;
17211  result.reserve(s_.size());
17212  strtk::replace_pattern(s_,pattern,replace_pattern,result);
17213  s_.assign(result);
17214  }
17215 
17216  template <typename DelimiterPredicate, typename OutputIterator>
17217  inline std::size_t split(const DelimiterPredicate& p,
17218  OutputIterator out,
17219  const split_options::type split_option = split_options::default_mode) const
17220  {
17221  return strtk::split(p,s_,out,split_option);
17222  }
17223 
17224  template <typename DelimiterPredicate,
17225  typename Allocator,
17226  template <typename,typename> class Sequence>
17227  inline std::size_t split(const DelimiterPredicate& p,
17228  Sequence<std::string,Allocator>& seq,
17229  const split_options::type split_option = split_options::default_mode) const
17230  {
17231  return strtk::split(p,s_,range_to_type_back_inserter(seq),split_option);
17232  }
17233 
17234  template <typename DelimiterPredicate, typename OutputIterator>
17235  inline std::size_t split_n(const DelimiterPredicate& p,
17236  const std::size_t& n,
17237  OutputIterator out,
17238  const split_options::type split_option = split_options::default_mode) const
17239  {
17240  return strtk::split_n(p,s_,n,out,split_option);
17241  }
17242 
17243  template <typename DelimiterPredicate,
17244  typename Allocator,
17245  template <typename,typename> class Sequence>
17246  inline std::size_t split_n(const DelimiterPredicate& p,
17247  const std::size_t& n,
17248  Sequence<std::string,Allocator>& seq,
17249  const split_options::type split_option = split_options::default_mode) const
17250  {
17251  return strtk::split_n(p,s_,n,range_to_type_back_inserter(seq),split_option);
17252  }
17253 
17254  template <typename T,
17255  typename Allocator,
17256  template <typename,typename> class Sequence>
17257  inline std::size_t parse(const std::string& delimiters, Sequence<T,Allocator>& seq) const
17258  {
17259  return strtk::parse(s_,delimiters,seq);
17260  }
17261 
17262  template <typename T,
17263  typename Allocator,
17264  template <typename,typename> class Sequence>
17265  inline std::size_t parse(const char* delimiters, Sequence<T,Allocator>& seq) const
17266  {
17267  return parse(std::string(delimiters),seq);
17268  }
17269 
17270  friend inline ext_string operator * (const std::size_t& n, const ext_string& s);
17271  friend inline ext_string operator * (const ext_string& s, const std::size_t& n);
17272 
17273  template <typename T>
17274  friend inline ext_string operator + (const ext_string& s, const T& t);
17275 
17276  template <typename T>
17277  friend inline ext_string operator + (const T& t, const ext_string& s);
17278 
17279  friend inline ext_string operator - (const ext_string& s, const std::string& pattern);
17280  friend inline ext_string operator - (const ext_string& s, const char* pattern);
17281  friend inline ext_string operator - (const ext_string& s, const ext_string& pattern);
17282 
17283  static inline ext_string all_digits()
17284  {
17285  static const ext_string digits("0123456789");
17286  return digits;
17287  }
17288 
17289  static inline ext_string all_letters()
17290  {
17291  static const ext_string letters("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
17292  return letters;
17293  }
17294 
17296  {
17297  static const ext_string letters("abcdefghijklmnopqrstuvwxyz");
17298  return letters;
17299  }
17300 
17302  {
17303  static const ext_string letters("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
17304  return letters;
17305  }
17306 
17307  static inline ext_string all_chars()
17308  {
17309  ext_string s;
17310  s.as_string().resize(256);
17311  strtk::iota(s.as_string().begin(),
17312  s.as_string().end(),
17313  static_cast<std::string::value_type>(0x00));
17314  return s;
17315  }
17316 
17317  private:
17318 
17319  std::string s_;
17320  };
17321 
17322  inline ext_string operator * (const std::size_t& n, const ext_string& s)
17323  {
17324  return ext_string(replicate(n, s.s_));
17325  }
17326 
17327  inline ext_string operator * (const ext_string& s, const std::size_t& n)
17328  {
17329  return ext_string(replicate(n, s.s_));
17330  }
17331 
17332  template <typename T>
17333  inline ext_string operator + (const ext_string& s, const T& t)
17334  {
17335  return ext_string(s.s_ + type_to_string(t));
17336  }
17337 
17338  template <typename T>
17339  inline ext_string operator + (const T& t, const ext_string& s)
17340  {
17341  return ext_string(type_to_string(t) + s.s_);
17342  }
17343 
17344  inline ext_string operator - (const ext_string& s, const std::string& pattern)
17345  {
17346  std::string tmp;
17347  tmp.reserve(s.s_.size());
17348  remove_pattern(s,pattern,tmp);
17349  return ext_string(tmp);
17350  }
17351 
17352  inline ext_string operator - (const ext_string& s, const char* pattern)
17353  {
17354  return s - std::string(pattern);
17355  }
17356 
17357  inline ext_string operator - (const ext_string& s, const ext_string& pattern)
17358  {
17359  return s - std::string(pattern.as_string());
17360  }
17361 
17362  static inline std::ostream& operator<<(std::ostream& os, const ext_string& es)
17363  {
17364  return (os << es.as_string());
17365  }
17366 
17367  namespace fileio
17368  {
17369 
17370  inline bool file_exists(const std::string& file_name)
17371  {
17372  std::ifstream file(file_name.c_str(), std::ios::binary);
17373  return ((!file) ? false : true);
17374  }
17375 
17376  inline std::size_t file_size(const std::string& file_name)
17377  {
17378  std::ifstream file(file_name.c_str(),std::ios::binary);
17379  if (!file) return 0;
17380  file.seekg (0, std::ios::end);
17381  return static_cast<std::size_t>(file.tellg());
17382  }
17383 
17384  inline bool load_file(const std::string& file_name, char* buffer, std::size_t buffer_size)
17385  {
17386  std::ifstream in_stream(file_name.c_str(),std::ios::binary);
17387  if (!in_stream) return false;
17388  in_stream.read(buffer,static_cast<std::streamsize>(buffer_size));
17389  in_stream.close();
17390  return true;
17391  }
17392 
17393  inline bool load_file(const std::string& file_name, std::string& buffer)
17394  {
17395  buffer.resize(file_size(file_name));
17396  return load_file(file_name,const_cast<char*>(buffer.data()),buffer.size());
17397  }
17398 
17399  inline bool write_file(const std::string& file_name, char* buffer, const std::size_t& buffer_size)
17400  {
17401  std::ofstream out_stream(file_name.c_str(),std::ios::binary);
17402  if (!out_stream) return false;
17403  out_stream.write(buffer,static_cast<std::streamsize>(buffer_size));
17404  out_stream.close();
17405  return true;
17406  }
17407 
17408  inline bool write_file(const std::string& file_name, const std::string& buffer)
17409  {
17410  return write_file(file_name,const_cast<char*>(buffer.data()),buffer.size());
17411  }
17412 
17413  inline bool copy_file(const std::string& src_file_name, const std::string& dest_file_name)
17414  {
17415  std::ifstream src_file(src_file_name.c_str(),std::ios::binary);
17416  std::ofstream dest_file(dest_file_name.c_str(),std::ios::binary);
17417  if (!src_file) return false;
17418  if (!dest_file) return false;
17419 
17420  static const std::size_t block_size = 16 * one_kilobyte;
17421  char buffer[block_size];
17422 
17423  std::size_t remaining_bytes = file_size(src_file_name);
17424 
17425  while (remaining_bytes >= block_size)
17426  {
17427  src_file.read(&buffer[0],static_cast<std::streamsize>(block_size));
17428  dest_file.write(&buffer[0],static_cast<std::streamsize>(block_size));
17429  remaining_bytes -= block_size;
17430  }
17431 
17432  if (remaining_bytes > 0)
17433  {
17434  src_file.read(&buffer[0],static_cast<std::streamsize>(remaining_bytes));
17435  dest_file.write(&buffer[0],static_cast<std::streamsize>(remaining_bytes));
17436  remaining_bytes = 0;
17437  }
17438 
17439  src_file.close();
17440  dest_file.close();
17441  return true;
17442  }
17443 
17444  inline bool concatenate(const std::string& file_name1,
17445  const std::string& file_name2,
17446  const std::string& output_file_name)
17447  {
17448  std::ifstream file1(file_name1.c_str(),std::ios::binary);
17449  std::ifstream file2(file_name2.c_str(),std::ios::binary);
17450  std::ofstream out_file(output_file_name.c_str(),std::ios::binary);
17451 
17452  if (!file1 || !file2 || !out_file) return false;
17453 
17454  static const std::size_t block_size = 16 * one_kilobyte;
17455  char buffer[block_size];
17456  unsigned int round = 0;
17457  std::size_t remaining_bytes = 0;
17458 
17459  while (round < 2)
17460  {
17461  std::ifstream& input_stream = ((0 == round) ? file1 : file2);
17462  remaining_bytes = ((0 == round) ? file_size(file_name1) : file_size(file_name2));
17463 
17464  while (remaining_bytes >= block_size)
17465  {
17466  input_stream.read(&buffer[0],static_cast<std::streamsize>(block_size));
17467  out_file.write(&buffer[0],static_cast<std::streamsize>(block_size));
17468  remaining_bytes -= block_size;
17469  }
17470 
17471  if (remaining_bytes > 0)
17472  {
17473  input_stream.read(&buffer[0],static_cast<std::streamsize>(remaining_bytes));
17474  out_file.write(&buffer[0],static_cast<std::streamsize>(remaining_bytes));
17475  remaining_bytes = 0;
17476  }
17477 
17478  input_stream.close();
17479  ++round;
17480  }
17481  out_file.close();
17482  return true;
17483  }
17484 
17485  inline bool files_identical(const std::string& file_name1, const std::string& file_name2)
17486  {
17487  std::ifstream file1(file_name1.c_str(),std::ios::binary);
17488  std::ifstream file2(file_name2.c_str(),std::ios::binary);
17489  if (!file1) return false;
17490  if (!file2) return false;
17491  if (file_size(file_name1) != file_size(file_name2)) return false;
17492 
17493  static const std::size_t block_size = 16 * one_kilobyte;
17494  char buffer1[block_size];
17495  char buffer2[block_size];
17496 
17497  std::size_t remaining_bytes = file_size(file_name1);
17498 
17499  while (remaining_bytes >= block_size)
17500  {
17501  file1.read(&buffer1[0],static_cast<std::streamsize>(block_size));
17502  file2.read(&buffer2[0],static_cast<std::streamsize>(block_size));
17503  if (0 != std::memcmp(buffer1,buffer2,block_size))
17504  return false;
17505  remaining_bytes -= block_size;
17506  }
17507 
17508  if (remaining_bytes > 0)
17509  {
17510  file1.read(&buffer1[0],static_cast<std::streamsize>(remaining_bytes));
17511  file2.read(&buffer2[0],static_cast<std::streamsize>(remaining_bytes));
17512  if (0 != std::memcmp(buffer1,buffer2,remaining_bytes))
17513  return false;
17514  remaining_bytes = 0;
17515  }
17516 
17517  file1.close();
17518  file2.close();
17519 
17520  return true;
17521  }
17522 
17523  namespace details
17524  {
17525  template <typename T>
17526  inline bool read_pod_proxy(std::ifstream& stream, T& t)
17527  {
17528  return (false == stream.read(reinterpret_cast<char*>(&t),
17529  static_cast<std::streamsize>(sizeof(T))).fail());
17530  }
17531 
17532  template <typename T>
17533  inline bool write_pod_proxy(std::ofstream& stream, const T& t)
17534  {
17535  return (false == stream.write(reinterpret_cast<char*>(&t),
17536  static_cast<std::streamsize>(sizeof(T))).fail());
17537  }
17538  }
17539 
17540  template <typename T1, typename T2, typename T3, typename T4,
17541  typename T5, typename T6, typename T7, typename T8,
17542  typename T9, typename T10>
17543  inline bool read_pod(std::ifstream& stream,
17544  T1& t1, T2& t2, T3& t3, T4& t4,
17545  T5& t5, T6& t6, T7& t7, T8& t8,
17546  T9& t9, T10& t10)
17547  {
17548  return details::read_pod_proxy(stream, t1) &&
17549  details::read_pod_proxy(stream, t2) &&
17550  details::read_pod_proxy(stream, t3) &&
17551  details::read_pod_proxy(stream, t4) &&
17552  details::read_pod_proxy(stream, t5) &&
17553  details::read_pod_proxy(stream, t6) &&
17554  details::read_pod_proxy(stream, t7) &&
17555  details::read_pod_proxy(stream, t8) &&
17556  details::read_pod_proxy(stream, t9) &&
17557  details::read_pod_proxy(stream,t10);
17558  }
17559 
17560  template <typename T1, typename T2, typename T3, typename T4,
17561  typename T5, typename T6, typename T7, typename T8,
17562  typename T9>
17563  inline bool read_pod(std::ifstream& stream,
17564  T1& t1, T2& t2, T3& t3, T4& t4,
17565  T5& t5, T6& t6, T7& t7, T8& t8,
17566  T9& t9)
17567  {
17568  return details::read_pod_proxy(stream,t1) &&
17569  details::read_pod_proxy(stream,t2) &&
17570  details::read_pod_proxy(stream,t3) &&
17571  details::read_pod_proxy(stream,t4) &&
17572  details::read_pod_proxy(stream,t5) &&
17573  details::read_pod_proxy(stream,t6) &&
17574  details::read_pod_proxy(stream,t7) &&
17575  details::read_pod_proxy(stream,t8) &&
17576  details::read_pod_proxy(stream,t9);
17577  }
17578 
17579  template <typename T1, typename T2, typename T3, typename T4,
17580  typename T5, typename T6, typename T7, typename T8>
17581  inline bool read_pod(std::ifstream& stream,
17582  T1& t1, T2& t2, T3& t3, T4& t4,
17583  T5& t5, T6& t6, T7& t7, T8& t8)
17584  {
17585  return details::read_pod_proxy(stream,t1) &&
17586  details::read_pod_proxy(stream,t2) &&
17587  details::read_pod_proxy(stream,t3) &&
17588  details::read_pod_proxy(stream,t4) &&
17589  details::read_pod_proxy(stream,t5) &&
17590  details::read_pod_proxy(stream,t6) &&
17591  details::read_pod_proxy(stream,t7) &&
17592  details::read_pod_proxy(stream,t8);
17593  }
17594 
17595  template <typename T1, typename T2, typename T3, typename T4,
17596  typename T5, typename T6, typename T7>
17597  inline bool read_pod(std::ifstream& stream,
17598  T1& t1, T2& t2, T3& t3, T4& t4,
17599  T5& t5, T6& t6, T7& t7)
17600  {
17601  return details::read_pod_proxy(stream,t1) &&
17602  details::read_pod_proxy(stream,t2) &&
17603  details::read_pod_proxy(stream,t3) &&
17604  details::read_pod_proxy(stream,t4) &&
17605  details::read_pod_proxy(stream,t5) &&
17606  details::read_pod_proxy(stream,t6) &&
17607  details::read_pod_proxy(stream,t7);
17608  }
17609 
17610  template <typename T1, typename T2, typename T3, typename T4,
17611  typename T5, typename T6>
17612  inline bool read_pod(std::ifstream& stream,
17613  T1& t1, T2& t2, T3& t3, T4& t4,
17614  T5& t5, T6& t6)
17615  {
17616  return details::read_pod_proxy(stream,t1) &&
17617  details::read_pod_proxy(stream,t2) &&
17618  details::read_pod_proxy(stream,t3) &&
17619  details::read_pod_proxy(stream,t4) &&
17620  details::read_pod_proxy(stream,t5) &&
17621  details::read_pod_proxy(stream,t6);
17622  }
17623 
17624  template <typename T1, typename T2, typename T3, typename T4,
17625  typename T5>
17626  inline bool read_pod(std::ifstream& stream,
17627  T1& t1, T2& t2, T3& t3, T4& t4,
17628  T5& t5)
17629  {
17630  return details::read_pod_proxy(stream,t1) &&
17631  details::read_pod_proxy(stream,t2) &&
17632  details::read_pod_proxy(stream,t3) &&
17633  details::read_pod_proxy(stream,t4) &&
17634  details::read_pod_proxy(stream,t5);
17635  }
17636 
17637  template <typename T1, typename T2, typename T3, typename T4>
17638  inline bool read_pod(std::ifstream& stream,
17639  T1& t1, T2& t2, T3& t3, T4& t4)
17640  {
17641  return details::read_pod_proxy(stream,t1) &&
17642  details::read_pod_proxy(stream,t2) &&
17643  details::read_pod_proxy(stream,t3) &&
17644  details::read_pod_proxy(stream,t4);
17645  }
17646 
17647  template <typename T1, typename T2, typename T3>
17648  inline bool read_pod(std::ifstream& stream,
17649  T1& t1, T2& t2, T3& t3)
17650  {
17651  return details::read_pod_proxy(stream,t1) &&
17652  details::read_pod_proxy(stream,t2) &&
17653  details::read_pod_proxy(stream,t3);
17654  }
17655 
17656  template <typename T1, typename T2>
17657  inline bool read_pod(std::ifstream& stream,
17658  T1& t1, T2& t2)
17659  {
17660  return details::read_pod_proxy(stream,t1) &&
17661  details::read_pod_proxy(stream,t2);
17662  }
17663 
17664  template <typename T>
17665  inline bool read_pod(std::ifstream& stream, T& t)
17666  {
17667  return details::read_pod_proxy(stream,t);
17668  }
17669 
17670  template <typename T, std::size_t N>
17671  inline bool read_pod(std::ifstream& stream, T (&t)[N])
17672  {
17673  return (false != stream.read(reinterpret_cast<char*>(&t[0]),sizeof(T) * N).fail());
17674  }
17675 
17676  template <typename T,
17677  typename Allocator,
17678  template <typename,typename> class Sequence>
17679  inline bool read_pod(std::ifstream& stream,
17680  const std::size_t& count,
17681  Sequence<T,Allocator>& sequence)
17682  {
17683  T t;
17684  for (std::size_t i = 0; i < count; ++i)
17685  {
17686  if (details::read_pod_proxy(stream,t))
17687  sequence.push_back(t);
17688  else
17689  return false;
17690  }
17691  return true;
17692  }
17693 
17694  template <typename T,
17695  typename Comparator,
17696  typename Allocator>
17697  inline bool read_pod(std::ifstream& stream,
17698  const std::size_t& count,
17699  std::set<T,Comparator,Allocator>& set)
17700  {
17701  T t;
17702  for (std::size_t i = 0; i < count; ++i)
17703  {
17704  if (details::read_pod_proxy(stream,t))
17705  set.insert(t);
17706  else
17707  return false;
17708  }
17709  return true;
17710  }
17711 
17712  template <typename T,
17713  typename Comparator,
17714  typename Allocator>
17715  inline bool read_pod(std::ifstream& stream,
17716  const std::size_t& count,
17717  std::multiset<T,Comparator,Allocator>& multiset)
17718  {
17719  T t;
17720  for (std::size_t i = 0; i < count; ++i)
17721  {
17722  if (details::read_pod_proxy(stream,t))
17723  multiset.insert(t);
17724  else
17725  return false;
17726  }
17727  return true;
17728  }
17729 
17730  template <typename T1, typename T2, typename T3, typename T4,
17731  typename T5, typename T6, typename T7, typename T8,
17732  typename T9, typename T10>
17733  inline bool write_pod(std::ofstream& stream,
17734  const T1& t1, const T2& t2, const T3& t3, const T4& t4,
17735  const T5& t5, const T6& t6, const T7& t7, const T8& t8,
17736  const T9& t9, const T10& t10)
17737  {
17738  return details::write_pod_proxy(stream, t1) &&
17739  details::write_pod_proxy(stream, t2) &&
17740  details::write_pod_proxy(stream, t3) &&
17741  details::write_pod_proxy(stream, t4) &&
17742  details::write_pod_proxy(stream, t5) &&
17743  details::write_pod_proxy(stream, t6) &&
17744  details::write_pod_proxy(stream, t7) &&
17745  details::write_pod_proxy(stream, t8) &&
17746  details::write_pod_proxy(stream, t9) &&
17747  details::write_pod_proxy(stream,t10);
17748  }
17749 
17750  template <typename T1, typename T2, typename T3, typename T4,
17751  typename T5, typename T6, typename T7, typename T8,
17752  typename T9>
17753  inline bool write_pod(std::ofstream& stream,
17754  const T1& t1, const T2& t2, const T3& t3, const T4& t4,
17755  const T5& t5, const T6& t6, const T7& t7, const T8& t8,
17756  const T9& t9)
17757  {
17758  return details::write_pod_proxy(stream,t1) &&
17759  details::write_pod_proxy(stream,t2) &&
17760  details::write_pod_proxy(stream,t3) &&
17761  details::write_pod_proxy(stream,t4) &&
17762  details::write_pod_proxy(stream,t5) &&
17763  details::write_pod_proxy(stream,t6) &&
17764  details::write_pod_proxy(stream,t7) &&
17765  details::write_pod_proxy(stream,t8) &&
17766  details::write_pod_proxy(stream,t9);
17767  }
17768 
17769  template <typename T1, typename T2, typename T3, typename T4,
17770  typename T5, typename T6, typename T7, typename T8>
17771  inline bool write_pod(std::ofstream& stream,
17772  const T1& t1, const T2& t2, const T3& t3, const T4& t4,
17773  const T5& t5, const T6& t6, const T7& t7, const T8& t8)
17774  {
17775  return details::write_pod_proxy(stream,t1) &&
17776  details::write_pod_proxy(stream,t2) &&
17777  details::write_pod_proxy(stream,t3) &&
17778  details::write_pod_proxy(stream,t4) &&
17779  details::write_pod_proxy(stream,t5) &&
17780  details::write_pod_proxy(stream,t6) &&
17781  details::write_pod_proxy(stream,t7) &&
17782  details::write_pod_proxy(stream,t8);
17783  }
17784 
17785  template <typename T1, typename T2, typename T3, typename T4,
17786  typename T5, typename T6, typename T7>
17787  inline bool write_pod(std::ofstream& stream,
17788  const T1& t1, const T2& t2, const T3& t3, const T4& t4,
17789  const T5& t5, const T6& t6, const T7& t7)
17790  {
17791  return details::write_pod_proxy(stream,t1) &&
17792  details::write_pod_proxy(stream,t2) &&
17793  details::write_pod_proxy(stream,t3) &&
17794  details::write_pod_proxy(stream,t4) &&
17795  details::write_pod_proxy(stream,t5) &&
17796  details::write_pod_proxy(stream,t6) &&
17797  details::write_pod_proxy(stream,t7);
17798  }
17799 
17800  template <typename T1, typename T2, typename T3, typename T4,
17801  typename T5, typename T6>
17802  inline bool write_pod(std::ofstream& stream,
17803  const T1& t1, const T2& t2, const T3& t3, const T4& t4,
17804  const T5& t5, const T6& t6)
17805  {
17806  return details::write_pod_proxy(stream,t1) &&
17807  details::write_pod_proxy(stream,t2) &&
17808  details::write_pod_proxy(stream,t3) &&
17809  details::write_pod_proxy(stream,t4) &&
17810  details::write_pod_proxy(stream,t5) &&
17811  details::write_pod_proxy(stream,t6);
17812  }
17813 
17814  template <typename T1, typename T2, typename T3, typename T4,
17815  typename T5>
17816  inline bool write_pod(std::ofstream& stream,
17817  const T1& t1, const T2& t2, const T3& t3, const T4& t4,
17818  const T5& t5)
17819  {
17820  return details::write_pod_proxy(stream,t1) &&
17821  details::write_pod_proxy(stream,t2) &&
17822  details::write_pod_proxy(stream,t3) &&
17823  details::write_pod_proxy(stream,t4) &&
17824  details::write_pod_proxy(stream,t5);
17825  }
17826 
17827  template <typename T1, typename T2, typename T3, typename T4>
17828  inline bool write_pod(std::ofstream& stream,
17829  const T1& t1, const T2& t2, const T3& t3, const T4& t4)
17830  {
17831  return details::write_pod_proxy(stream,t1) &&
17832  details::write_pod_proxy(stream,t2) &&
17833  details::write_pod_proxy(stream,t3) &&
17834  details::write_pod_proxy(stream,t4);
17835  }
17836 
17837  template <typename T1, typename T2, typename T3>
17838  inline bool write_pod(std::ofstream& stream,
17839  const T1& t1, const T2& t2, const T3& t3)
17840  {
17841  return details::write_pod_proxy(stream,t1) &&
17842  details::write_pod_proxy(stream,t2) &&
17843  details::write_pod_proxy(stream,t3);
17844  }
17845 
17846  template <typename T1, typename T2>
17847  inline bool write_pod(std::ofstream& stream,
17848  const T1& t1, const T2& t2)
17849  {
17850  return details::write_pod_proxy(stream,t1) &&
17851  details::write_pod_proxy(stream,t2);
17852  }
17853 
17854  template <typename T>
17855  inline bool write_pod(std::ofstream& stream, const T& t)
17856  {
17857  return details::write_pod_proxy(stream,t);
17858  }
17859 
17860  template <typename T, std::size_t N>
17861  inline bool write_pod(std::ofstream& stream, T (&t)[N])
17862  {
17863  return (false != stream.write(reinterpret_cast<char*>(&t[0]),sizeof(T) * N).fail());
17864  }
17865 
17866  template <typename T,
17867  typename Allocator,
17868  template <typename,typename> class Sequence>
17869  inline bool write_pod(std::ofstream& stream,
17870  const Sequence<T,Allocator>& sequence)
17871  {
17872  typename Sequence<T,Allocator>::iterator itr = sequence.begin();
17873  typename Sequence<T,Allocator>::iterator end = sequence.end();
17874  while (end != itr)
17875  {
17876  if (details::write_pod_proxy(stream,*itr))
17877  ++itr;
17878  else
17879  return false;
17880  }
17881  }
17882 
17883  template <typename T,
17884  typename Comparator,
17885  typename Allocator>
17886  inline bool write_pod(std::ofstream& stream,
17887  const std::set<T,Comparator,Allocator>& set)
17888  {
17889  typename std::set<T,Comparator,Allocator>::iterator itr = set.begin();
17890  typename std::set<T,Comparator,Allocator>::iterator end = set.end();
17891  while (end != itr)
17892  {
17893  if (details::write_pod_proxy(stream,*itr))
17894  ++itr;
17895  else
17896  return false;
17897  }
17898  }
17899 
17900  template <typename T,
17901  typename Comparator,
17902  typename Allocator>
17903  inline bool write_pod(std::ofstream& stream,
17904  const std::multiset<T,Comparator,Allocator>& multiset)
17905  {
17906  typename std::multiset<T,Comparator,Allocator>::iterator itr = multiset.begin();
17907  typename std::multiset<T,Comparator,Allocator>::iterator end = multiset.end();
17908  while (end != itr)
17909  {
17910  if (details::write_pod_proxy(stream,*itr))
17911  ++itr;
17912  else
17913  return false;
17914  }
17915  }
17916 
17917  inline bool read_at_offset(std::ifstream& stream,
17918  const std::size_t& offset,
17919  char* buffer,
17920  const std::size_t& buffer_size)
17921  {
17922  if (!stream) return false;
17923  stream.seekg(static_cast<std::ifstream::off_type>(offset),std::ios_base::beg);
17924  if (stream.fail()) return false;
17925  stream.read(buffer,static_cast<std::streamsize>(buffer_size));
17926  if (stream.fail()) return false;
17927  stream.close();
17928  return true;
17929  }
17930 
17931  inline bool read_at_offset(const std::string& file_name,
17932  const std::size_t& offset,
17933  char* buffer,
17934  const std::size_t& buffer_size)
17935  {
17936  std::ifstream stream(file_name.c_str(), std::ios::in | std::ios::binary);
17937  if (!stream) return false;
17938  return read_at_offset(stream,offset,buffer,buffer_size);
17939  }
17940 
17941  inline bool read_at_offset(const std::string& file_name,
17942  const std::size_t& offset,
17943  std::string& buffer,
17944  const std::size_t& buffer_size)
17945  {
17946  std::ifstream stream(file_name.c_str(), std::ios::in | std::ios::binary);
17947  if (!stream) return false;
17948  buffer.resize(buffer_size);
17949  return read_at_offset(stream,
17950  offset,
17951  const_cast<char*>(buffer.data()),
17952  buffer_size);
17953  }
17954 
17955  } // namespace fileio
17956 
17957  template <typename T1, typename T2, typename T3, typename T4,
17958  typename T5, typename T6, typename T7, typename T8,
17959  typename T9, typename T10, typename T11, typename T12>
17960  inline unsigned char* read_pod(unsigned char* data,
17961  T1& t1, T2& t2, T3& t3, T4& t4,
17962  T5& t5, T6& t6, T7& t7, T8& t8,
17963  T9& t9, T10& t10, T11& t11, T12& t12)
17964  {
17965  t1 = (*reinterpret_cast< T1*>(data)); data += sizeof( T1);
17966  t2 = (*reinterpret_cast< T2*>(data)); data += sizeof( T2);
17967  t3 = (*reinterpret_cast< T3*>(data)); data += sizeof( T3);
17968  t4 = (*reinterpret_cast< T4*>(data)); data += sizeof( T4);
17969  t5 = (*reinterpret_cast< T5*>(data)); data += sizeof( T5);
17970  t6 = (*reinterpret_cast< T6*>(data)); data += sizeof( T6);
17971  t7 = (*reinterpret_cast< T7*>(data)); data += sizeof( T7);
17972  t8 = (*reinterpret_cast< T8*>(data)); data += sizeof( T8);
17973  t9 = (*reinterpret_cast< T9*>(data)); data += sizeof( T9);
17974  t10 = (*reinterpret_cast<T10*>(data)); data += sizeof(T10);
17975  t11 = (*reinterpret_cast<T11*>(data)); data += sizeof(T11);
17976  t12 = (*reinterpret_cast<T12*>(data)); data += sizeof(T12);
17977  return data;
17978  }
17979 
17980  template <typename T1, typename T2, typename T3, typename T4,
17981  typename T5, typename T6, typename T7, typename T8,
17982  typename T9, typename T10, typename T11>
17983  inline unsigned char* read_pod(unsigned char* data,
17984  T1& t1, T2& t2, T3& t3, T4& t4,
17985  T5& t5, T6& t6, T7& t7, T8& t8,
17986  T9& t9, T10& t10, T11& t11)
17987  {
17988  t1 = (*reinterpret_cast< T1*>(data)); data += sizeof( T1);
17989  t2 = (*reinterpret_cast< T2*>(data)); data += sizeof( T2);
17990  t3 = (*reinterpret_cast< T3*>(data)); data += sizeof( T3);
17991  t4 = (*reinterpret_cast< T4*>(data)); data += sizeof( T4);
17992  t5 = (*reinterpret_cast< T5*>(data)); data += sizeof( T5);
17993  t6 = (*reinterpret_cast< T6*>(data)); data += sizeof( T6);
17994  t7 = (*reinterpret_cast< T7*>(data)); data += sizeof( T7);
17995  t8 = (*reinterpret_cast< T8*>(data)); data += sizeof( T8);
17996  t9 = (*reinterpret_cast< T9*>(data)); data += sizeof( T9);
17997  t10 = (*reinterpret_cast<T10*>(data)); data += sizeof(T10);
17998  t11 = (*reinterpret_cast<T11*>(data)); data += sizeof(T11);
17999  return data;
18000  }
18001 
18002  template <typename T1, typename T2, typename T3, typename T4,
18003  typename T5, typename T6, typename T7, typename T8,
18004  typename T9, typename T10>
18005  inline unsigned char* read_pod(unsigned char* data,
18006  T1& t1, T2& t2, T3& t3, T4& t4,
18007  T5& t5, T6& t6, T7& t7, T8& t8,
18008  T9& t9, T10& t10)
18009  {
18010  t1 = (*reinterpret_cast< T1*>(data)); data += sizeof( T1);
18011  t2 = (*reinterpret_cast< T2*>(data)); data += sizeof( T2);
18012  t3 = (*reinterpret_cast< T3*>(data)); data += sizeof( T3);
18013  t4 = (*reinterpret_cast< T4*>(data)); data += sizeof( T4);
18014  t5 = (*reinterpret_cast< T5*>(data)); data += sizeof( T5);
18015  t6 = (*reinterpret_cast< T6*>(data)); data += sizeof( T6);
18016  t7 = (*reinterpret_cast< T7*>(data)); data += sizeof( T7);
18017  t8 = (*reinterpret_cast< T8*>(data)); data += sizeof( T8);
18018  t9 = (*reinterpret_cast< T9*>(data)); data += sizeof( T9);
18019  t10 = (*reinterpret_cast<T10*>(data)); data += sizeof(T10);
18020  return data;
18021  }
18022 
18023  template <typename T1, typename T2, typename T3, typename T4,
18024  typename T5, typename T6, typename T7, typename T8,
18025  typename T9>
18026  inline unsigned char* read_pod(unsigned char* data,
18027  T1& t1, T2& t2, T3& t3, T4& t4,
18028  T5& t5, T6& t6, T7& t7, T8& t8,
18029  T9& t9)
18030  {
18031  t1 = (*reinterpret_cast<T1*>(data)); data += sizeof(T1);
18032  t2 = (*reinterpret_cast<T2*>(data)); data += sizeof(T2);
18033  t3 = (*reinterpret_cast<T3*>(data)); data += sizeof(T3);
18034  t4 = (*reinterpret_cast<T4*>(data)); data += sizeof(T4);
18035  t5 = (*reinterpret_cast<T5*>(data)); data += sizeof(T5);
18036  t6 = (*reinterpret_cast<T6*>(data)); data += sizeof(T6);
18037  t7 = (*reinterpret_cast<T7*>(data)); data += sizeof(T7);
18038  t8 = (*reinterpret_cast<T8*>(data)); data += sizeof(T8);
18039  t9 = (*reinterpret_cast<T9*>(data)); data += sizeof(T9);
18040  return data;
18041  }
18042 
18043  template <typename T1, typename T2, typename T3, typename T4,
18044  typename T5, typename T6, typename T7, typename T8>
18045  inline unsigned char* read_pod(unsigned char* data,
18046  T1& t1, T2& t2, T3& t3, T4& t4,
18047  T5& t5, T6& t6, T7& t7, T8& t8)
18048  {
18049  t1 = (*reinterpret_cast<T1*>(data)); data += sizeof(T1);
18050  t2 = (*reinterpret_cast<T2*>(data)); data += sizeof(T2);
18051  t3 = (*reinterpret_cast<T3*>(data)); data += sizeof(T3);
18052  t4 = (*reinterpret_cast<T4*>(data)); data += sizeof(T4);
18053  t5 = (*reinterpret_cast<T5*>(data)); data += sizeof(T5);
18054  t6 = (*reinterpret_cast<T6*>(data)); data += sizeof(T6);
18055  t7 = (*reinterpret_cast<T7*>(data)); data += sizeof(T7);
18056  t8 = (*reinterpret_cast<T8*>(data)); data += sizeof(T8);
18057  return data;
18058  }
18059 
18060  template <typename T1, typename T2, typename T3, typename T4,
18061  typename T5, typename T6, typename T7>
18062  inline unsigned char* read_pod(unsigned char* data,
18063  T1& t1, T2& t2, T3& t3, T4& t4,
18064  T5& t5, T6& t6, T7& t7)
18065  {
18066  t1 = (*reinterpret_cast<T1*>(data)); data += sizeof(T1);
18067  t2 = (*reinterpret_cast<T2*>(data)); data += sizeof(T2);
18068  t3 = (*reinterpret_cast<T3*>(data)); data += sizeof(T3);
18069  t4 = (*reinterpret_cast<T4*>(data)); data += sizeof(T4);
18070  t5 = (*reinterpret_cast<T5*>(data)); data += sizeof(T5);
18071  t6 = (*reinterpret_cast<T6*>(data)); data += sizeof(T6);
18072  t7 = (*reinterpret_cast<T7*>(data)); data += sizeof(T7);
18073  return data;
18074  }
18075 
18076  template <typename T1, typename T2, typename T3, typename T4,
18077  typename T5, typename T6>
18078  inline unsigned char* read_pod(unsigned char* data,
18079  T1& t1, T2& t2, T3& t3, T4& t4,
18080  T5& t5, T6& t6)
18081  {
18082  t1 = (*reinterpret_cast<T1*>(data)); data += sizeof(T1);
18083  t2 = (*reinterpret_cast<T2*>(data)); data += sizeof(T2);
18084  t3 = (*reinterpret_cast<T3*>(data)); data += sizeof(T3);
18085  t4 = (*reinterpret_cast<T4*>(data)); data += sizeof(T4);
18086  t5 = (*reinterpret_cast<T5*>(data)); data += sizeof(T5);
18087  t6 = (*reinterpret_cast<T6*>(data)); data += sizeof(T6);
18088  return data;
18089  }
18090 
18091  template <typename T1, typename T2, typename T3, typename T4,
18092  typename T5>
18093  inline unsigned char* read_pod(unsigned char* data,
18094  T1& t1, T2& t2, T3& t3, T4& t4,
18095  T5& t5)
18096  {
18097  t1 = (*reinterpret_cast<T1*>(data)); data += sizeof(T1);
18098  t2 = (*reinterpret_cast<T2*>(data)); data += sizeof(T2);
18099  t3 = (*reinterpret_cast<T3*>(data)); data += sizeof(T3);
18100  t4 = (*reinterpret_cast<T4*>(data)); data += sizeof(T4);
18101  t5 = (*reinterpret_cast<T5*>(data)); data += sizeof(T5);
18102  return data;
18103  }
18104 
18105  template <typename T1, typename T2, typename T3, typename T4>
18106  inline unsigned char* read_pod(unsigned char* data,
18107  T1& t1, T2& t2, T3& t3, T4& t4)
18108  {
18109  t1 = (*reinterpret_cast<T1*>(data)); data += sizeof(T1);
18110  t2 = (*reinterpret_cast<T2*>(data)); data += sizeof(T2);
18111  t3 = (*reinterpret_cast<T3*>(data)); data += sizeof(T3);
18112  t4 = (*reinterpret_cast<T4*>(data)); data += sizeof(T4);
18113  return data;
18114  }
18115 
18116  template <typename T1, typename T2, typename T3>
18117  inline unsigned char* read_pod(unsigned char* data,
18118  T1& t1, T2& t2, T3& t3)
18119  {
18120  t1 = (*reinterpret_cast<T1*>(data)); data += sizeof(T1);
18121  t2 = (*reinterpret_cast<T2*>(data)); data += sizeof(T2);
18122  t3 = (*reinterpret_cast<T3*>(data)); data += sizeof(T3);
18123  return data;
18124  }
18125 
18126  template <typename T1, typename T2>
18127  inline unsigned char* read_pod(unsigned char* data,
18128  T1& t1, T2& t2)
18129  {
18130  t1 = (*reinterpret_cast<T1*>(data)); data += sizeof(T1);
18131  t2 = (*reinterpret_cast<T2*>(data)); data += sizeof(T2);
18132  return data;
18133  }
18134 
18135  template <typename T1>
18136  inline unsigned char* read_pod(unsigned char* data,
18137  T1& t1)
18138  {
18139  t1 = (*reinterpret_cast<T1*>(data)); data += sizeof(T1);
18140  return data;
18141  }
18142 
18143  template <typename T, std::size_t N>
18144  inline unsigned char* read_pod(unsigned char* data, T (&t)[N])
18145  {
18146  T* begin = reinterpret_cast<T*>(data);
18147  T* end = begin + N;
18148  std::copy(begin,end,&t[0]);
18149  return data + (N * sizeof(T));
18150  }
18151 
18152  template <typename T,
18153  typename Allocator,
18154  template <typename,typename> class Sequence>
18155  inline unsigned char* read_pod(unsigned char* data,
18156  const std::size_t& n,
18157  const Sequence<T,Allocator>& sequence)
18158  {
18159  T* ptr = reinterpret_cast<T>(data);
18160  std::copy(ptr, ptr + n, std::back_inserter(sequence));
18161  return data + (sequence.size() * sizeof(T));
18162  }
18163 
18164  template <typename T,
18165  typename Comparator,
18166  typename Allocator>
18167  inline unsigned char* read_pod(unsigned char* data,
18168  const std::size_t& n,
18169  const std::set<T,Comparator,Allocator>& set)
18170  {
18171  T* ptr = reinterpret_cast<T>(data);
18172  std::copy(ptr, ptr + n, std::inserter(set,set.begin()));
18173  return data + (set.size() * sizeof(T));
18174  }
18175 
18176  template <typename T,
18177  typename Comparator,
18178  typename Allocator>
18179  inline unsigned char* read_pod(unsigned char* data,
18180  const std::size_t& n,
18181  const std::multiset<T,Comparator,Allocator>& multiset)
18182  {
18183  T* ptr = reinterpret_cast<T>(data);
18184  std::copy(ptr, ptr + n, std::inserter(multiset,multiset.begin()));
18185  return data + (multiset.size() * sizeof(T));
18186  }
18187 
18188  template <typename T1, typename T2, typename T3, typename T4,
18189  typename T5, typename T6, typename T7, typename T8,
18190  typename T9, typename T10, typename T11, typename T12>
18191  inline unsigned char* write_pod(unsigned char* data,
18192  const T1& t1, const T2& t2, const T3& t3, const T4& t4,
18193  const T5& t5, const T6& t6, const T7& t7, const T8& t8,
18194  const T9& t9, const T10& t10, const T11& t11, const T12& t12)
18195  {
18196  (*reinterpret_cast< T1*>(data)) = t1; data += sizeof( T1);
18197  (*reinterpret_cast< T2*>(data)) = t2; data += sizeof( T2);
18198  (*reinterpret_cast< T3*>(data)) = t3; data += sizeof( T3);
18199  (*reinterpret_cast< T4*>(data)) = t4; data += sizeof( T4);
18200  (*reinterpret_cast< T5*>(data)) = t5; data += sizeof( T5);
18201  (*reinterpret_cast< T6*>(data)) = t6; data += sizeof( T6);
18202  (*reinterpret_cast< T7*>(data)) = t7; data += sizeof( T7);
18203  (*reinterpret_cast< T8*>(data)) = t8; data += sizeof( T8);
18204  (*reinterpret_cast< T9*>(data)) = t9; data += sizeof( T9);
18205  (*reinterpret_cast<T10*>(data)) = t10; data += sizeof(T10);
18206  (*reinterpret_cast<T11*>(data)) = t11; data += sizeof(T11);
18207  (*reinterpret_cast<T12*>(data)) = t12; data += sizeof(T12);
18208  return data;
18209  }
18210 
18211  template <typename T1, typename T2, typename T3, typename T4,
18212  typename T5, typename T6, typename T7, typename T8,
18213  typename T9, typename T10, typename T11>
18214  inline unsigned char* write_pod(unsigned char* data,
18215  const T1& t1, const T2& t2, const T3& t3, const T4& t4,
18216  const T5& t5, const T6& t6, const T7& t7, const T8& t8,
18217  const T9& t9, const T10& t10, const T11& t11)
18218  {
18219  (*reinterpret_cast< T1*>(data)) = t1; data += sizeof( T1);
18220  (*reinterpret_cast< T2*>(data)) = t2; data += sizeof( T2);
18221  (*reinterpret_cast< T3*>(data)) = t3; data += sizeof( T3);
18222  (*reinterpret_cast< T4*>(data)) = t4; data += sizeof( T4);
18223  (*reinterpret_cast< T5*>(data)) = t5; data += sizeof( T5);
18224  (*reinterpret_cast< T6*>(data)) = t6; data += sizeof( T6);
18225  (*reinterpret_cast< T7*>(data)) = t7; data += sizeof( T7);
18226  (*reinterpret_cast< T8*>(data)) = t8; data += sizeof( T8);
18227  (*reinterpret_cast< T9*>(data)) = t9; data += sizeof( T9);
18228  (*reinterpret_cast<T10*>(data)) = t10; data += sizeof(T10);
18229  (*reinterpret_cast<T11*>(data)) = t11; data += sizeof(T11);
18230  return data;
18231  }
18232 
18233  template <typename T1, typename T2, typename T3, typename T4,
18234  typename T5, typename T6, typename T7, typename T8,
18235  typename T9, typename T10>
18236  inline unsigned char* write_pod(unsigned char* data,
18237  const T1& t1, const T2& t2, const T3& t3, const T4& t4,
18238  const T5& t5, const T6& t6, const T7& t7, const T8& t8,
18239  const T9& t9, const T10& t10)
18240  {
18241  (*reinterpret_cast< T1*>(data)) = t1; data += sizeof( T1);
18242  (*reinterpret_cast< T2*>(data)) = t2; data += sizeof( T2);
18243  (*reinterpret_cast< T3*>(data)) = t3; data += sizeof( T3);
18244  (*reinterpret_cast< T4*>(data)) = t4; data += sizeof( T4);
18245  (*reinterpret_cast< T5*>(data)) = t5; data += sizeof( T5);
18246  (*reinterpret_cast< T6*>(data)) = t6; data += sizeof( T6);
18247  (*reinterpret_cast< T7*>(data)) = t7; data += sizeof( T7);
18248  (*reinterpret_cast< T8*>(data)) = t8; data += sizeof( T8);
18249  (*reinterpret_cast< T9*>(data)) = t9; data += sizeof( T9);
18250  (*reinterpret_cast<T10*>(data)) = t10; data += sizeof(T10);
18251  return data;
18252  }
18253 
18254  template <typename T1, typename T2, typename T3, typename T4,
18255  typename T5, typename T6, typename T7, typename T8,
18256  typename T9>
18257  inline unsigned char* write_pod(unsigned char* data,
18258  const T1& t1, const T2& t2, const T3& t3, const T4& t4,
18259  const T5& t5, const T6& t6, const T7& t7, const T8& t8,
18260  const T9& t9)
18261  {
18262  (*reinterpret_cast<T1*>(data)) = t1; data += sizeof(T1);
18263  (*reinterpret_cast<T2*>(data)) = t2; data += sizeof(T2);
18264  (*reinterpret_cast<T3*>(data)) = t3; data += sizeof(T3);
18265  (*reinterpret_cast<T4*>(data)) = t4; data += sizeof(T4);
18266  (*reinterpret_cast<T5*>(data)) = t5; data += sizeof(T5);
18267  (*reinterpret_cast<T6*>(data)) = t6; data += sizeof(T6);
18268  (*reinterpret_cast<T7*>(data)) = t7; data += sizeof(T7);
18269  (*reinterpret_cast<T8*>(data)) = t8; data += sizeof(T8);
18270  (*reinterpret_cast<T9*>(data)) = t9; data += sizeof(T9);
18271  return data;
18272  }
18273 
18274  template <typename T1, typename T2, typename T3, typename T4,
18275  typename T5, typename T6, typename T7, typename T8>
18276  inline unsigned char* write_pod(unsigned char* data,
18277  const T1& t1, const T2& t2, const T3& t3, const T4& t4,
18278  const T5& t5, const T6& t6, const T7& t7, const T8& t8)
18279  {
18280  (*reinterpret_cast<T1*>(data)) = t1; data += sizeof(T1);
18281  (*reinterpret_cast<T2*>(data)) = t2; data += sizeof(T2);
18282  (*reinterpret_cast<T3*>(data)) = t3; data += sizeof(T3);
18283  (*reinterpret_cast<T4*>(data)) = t4; data += sizeof(T4);
18284  (*reinterpret_cast<T5*>(data)) = t5; data += sizeof(T5);
18285  (*reinterpret_cast<T6*>(data)) = t6; data += sizeof(T6);
18286  (*reinterpret_cast<T7*>(data)) = t7; data += sizeof(T7);
18287  (*reinterpret_cast<T8*>(data)) = t8; data += sizeof(T8);
18288  return data;
18289  }
18290 
18291  template <typename T1, typename T2, typename T3, typename T4,
18292  typename T5, typename T6, typename T7>
18293  inline unsigned char* write_pod(unsigned char* data,
18294  const T1& t1, const T2& t2, const T3& t3, const T4& t4,
18295  const T5& t5, const T6& t6, const T7& t7)
18296  {
18297  (*reinterpret_cast<T1*>(data)) = t1; data += sizeof(T1);
18298  (*reinterpret_cast<T2*>(data)) = t2; data += sizeof(T2);
18299  (*reinterpret_cast<T3*>(data)) = t3; data += sizeof(T3);
18300  (*reinterpret_cast<T4*>(data)) = t4; data += sizeof(T4);
18301  (*reinterpret_cast<T5*>(data)) = t5; data += sizeof(T5);
18302  (*reinterpret_cast<T6*>(data)) = t6; data += sizeof(T6);
18303  (*reinterpret_cast<T7*>(data)) = t7; data += sizeof(T7);
18304  return data;
18305  }
18306 
18307  template <typename T1, typename T2, typename T3, typename T4,
18308  typename T5, typename T6>
18309  inline unsigned char* write_pod(unsigned char* data,
18310  const T1& t1, const T2& t2, const T3& t3, const T4& t4,
18311  const T5& t5, const T6& t6)
18312  {
18313  (*reinterpret_cast<T1*>(data)) = t1; data += sizeof(T1);
18314  (*reinterpret_cast<T2*>(data)) = t2; data += sizeof(T2);
18315  (*reinterpret_cast<T3*>(data)) = t3; data += sizeof(T3);
18316  (*reinterpret_cast<T4*>(data)) = t4; data += sizeof(T4);
18317  (*reinterpret_cast<T5*>(data)) = t5; data += sizeof(T5);
18318  (*reinterpret_cast<T6*>(data)) = t6; data += sizeof(T6);
18319  return data;
18320  }
18321 
18322  template <typename T1, typename T2, typename T3, typename T4,
18323  typename T5>
18324  inline unsigned char* write_pod(unsigned char* data,
18325  const T1& t1, const T2& t2, const T3& t3, const T4& t4,
18326  const T5& t5)
18327  {
18328  (*reinterpret_cast<T1*>(data)) = t1; data += sizeof(T1);
18329  (*reinterpret_cast<T2*>(data)) = t2; data += sizeof(T2);
18330  (*reinterpret_cast<T3*>(data)) = t3; data += sizeof(T3);
18331  (*reinterpret_cast<T4*>(data)) = t4; data += sizeof(T4);
18332  (*reinterpret_cast<T5*>(data)) = t5; data += sizeof(T5);
18333  return data;
18334  }
18335 
18336  template <typename T1, typename T2, typename T3, typename T4>
18337  inline unsigned char* write_pod(unsigned char* data,
18338  const T1& t1, const T2& t2, const T3& t3, const T4& t4)
18339  {
18340  (*reinterpret_cast<T1*>(data)) = t1; data += sizeof(T1);
18341  (*reinterpret_cast<T2*>(data)) = t2; data += sizeof(T2);
18342  (*reinterpret_cast<T3*>(data)) = t3; data += sizeof(T3);
18343  (*reinterpret_cast<T4*>(data)) = t4; data += sizeof(T4);
18344  return data;
18345  }
18346 
18347  template <typename T1, typename T2, typename T3>
18348  inline unsigned char* write_pod(unsigned char* data,
18349  const T1& t1, const T2& t2, const T3& t3)
18350  {
18351  (*reinterpret_cast<T1*>(data)) = t1; data += sizeof(T1);
18352  (*reinterpret_cast<T2*>(data)) = t2; data += sizeof(T2);
18353  (*reinterpret_cast<T3*>(data)) = t3; data += sizeof(T3);
18354  return data;
18355  }
18356 
18357  template <typename T1, typename T2>
18358  inline unsigned char* write_pod(unsigned char* data,
18359  const T1& t1, const T2& t2)
18360  {
18361  (*reinterpret_cast<T1*>(data)) = t1; data += sizeof(T1);
18362  (*reinterpret_cast<T2*>(data)) = t2; data += sizeof(T2);
18363  return data;
18364  }
18365 
18366  template <typename T1>
18367  inline unsigned char* write_pod(unsigned char* data,
18368  const T1& t1)
18369  {
18370  (*reinterpret_cast<T1*>(data)) = t1; data += sizeof(T1);
18371  return data;
18372  }
18373 
18374  template <typename T, std::size_t N>
18375  inline unsigned char* write_pod(unsigned char* data, const T (&t)[N])
18376  {
18377  T* ptr = reinterpret_cast<T*>(data);
18378  std::copy(t,t + N,ptr);
18379  return data + (N * sizeof(T));
18380  }
18381 
18382  template <typename T,
18383  typename Allocator,
18384  template <typename,typename> class Sequence>
18385  inline unsigned char* write_pod(unsigned char* data,
18386  const Sequence<T,Allocator>& sequence)
18387  {
18388  T* ptr = reinterpret_cast<T>(data);
18389  std::copy(sequence.begin(),sequence.end(),ptr);
18390  return data + (sequence.size() * sizeof(T));
18391  }
18392 
18393  template <typename T,
18394  typename Comparator,
18395  typename Allocator>
18396  inline unsigned char* write_pod(unsigned char* data,
18397  const std::set<T,Comparator,Allocator>& set)
18398  {
18399  T* ptr = reinterpret_cast<T>(data);
18400  std::copy(set.begin(),set.end(),ptr);
18401  return data + (set.size() * sizeof(T));
18402  }
18403 
18404  template <typename T,
18405  typename Comparator,
18406  typename Allocator>
18407  inline unsigned char* write_pod(unsigned char* data,
18408  const std::multiset<T,Comparator,Allocator>& multiset)
18409  {
18410  T* ptr = reinterpret_cast<T>(data);
18411  std::copy(multiset.begin(),multiset.end(),ptr);
18412  return data + (multiset.size() * sizeof(T));
18413  }
18414 
18416  {
18417  private:
18418 
18419  typedef const unsigned char* itr_type;
18420 
18421  inline bool condition_equal(const itr_type begin, const itr_type end) const
18422  {
18423  if (s.size() == static_cast<std::size_t>(std::distance(begin,end)))
18424  {
18425  return std::equal(s_begin,s_end,begin);
18426  }
18427  else
18428  return false;
18429  }
18430 
18431  inline bool condition_notequal(const itr_type begin, const itr_type end) const
18432  {
18433  if (s.size() == static_cast<std::size_t>(std::distance(begin,end)))
18434  {
18435  return !std::equal(s_begin,s_end,begin);
18436  }
18437  else
18438  return true;
18439  }
18440 
18441  inline bool condition_like(const itr_type begin, const itr_type end) const
18442  {
18443  return match(s_begin,s_end,begin,end,(unsigned char)'*',(unsigned char)'?');
18444  }
18445 
18446  inline bool condition_begins_with(const itr_type begin, const itr_type end) const
18447  {
18448  if (s.size() == static_cast<std::size_t>(std::distance(begin,end)))
18449  {
18450  return strtk::begins_with(s_begin,s_end,begin,end);
18451  }
18452  else
18453  return false;
18454  }
18455 
18456  inline bool condition_ends_with(const itr_type begin, const itr_type end) const
18457  {
18458  if (s.size() == static_cast<std::size_t>(std::distance(begin,end)))
18459  {
18460  return strtk::ends_with(s_begin,s_end,begin,end);
18461  }
18462  else
18463  return false;
18464  }
18465 
18466  inline bool condition_within(const itr_type begin, const itr_type end) const
18467  {
18468  if (s.size() <= static_cast<std::size_t>(std::distance(begin,end)))
18469  {
18470  return (end != std::search(begin,end,s_begin,s_end));
18471  }
18472  else
18473  return false;
18474  }
18475 
18476  inline bool condition_notwithin(const itr_type begin, const itr_type end) const
18477  {
18478  if (s.size() <= static_cast<std::size_t>(std::distance(begin,end)))
18479  {
18480  return (end == std::search(begin,end,s_begin,s_end));
18481  }
18482  else
18483  return true;
18484  }
18485 
18486  typedef bool (string_condition::*condition_method)(const itr_type begin, const itr_type end) const;
18487 
18488  public:
18489 
18491  {
18492  equal = 0,
18493  notequal = 1,
18494  like = 2,
18497  within = 16,
18498  notwithin = 32
18499  };
18500 
18501  inline explicit string_condition(condition_type cond_type, const std::string& str)
18502  : cond_type_(cond_type),
18503  s(str),
18504  s_begin(reinterpret_cast<const unsigned char*>(s.data())),
18505  s_end(reinterpret_cast<const unsigned char*>(s.data() + str.size())),
18506  condition_method_(0)
18507  {
18508  switch (cond_type_)
18509  {
18510  case equal : condition_method_ = &string_condition::condition_equal;
18511  break;
18512  case notequal : condition_method_ = &string_condition::condition_notequal;
18513  break;
18514  case like : condition_method_ = &string_condition::condition_like;
18515  break;
18516  case begins_with : condition_method_ = &string_condition::condition_begins_with;
18517  break;
18518  case ends_with : condition_method_ = &string_condition::condition_ends_with;
18519  break;
18520  case within : condition_method_ = &string_condition::condition_within;
18521  break;
18522  case notwithin : condition_method_ = &string_condition::condition_notwithin;
18523  break;
18524  }
18525  }
18526 
18527  template <typename Iterator>
18528  bool operator()(const Iterator begin, const Iterator end)
18529  {
18530  return ((*this).*condition_method_)(begin,end);
18531  }
18532 
18533  bool operator()(const std::string& str)
18534  {
18535  return operator()(reinterpret_cast<const unsigned char*>(str.data()),
18536  reinterpret_cast<const unsigned char*>(str.data() + str.size()));
18537  }
18538 
18539  private:
18540 
18541  condition_type cond_type_;
18542  std::string s;
18543  const unsigned char* s_begin;
18544  const unsigned char* s_end;
18545  condition_method condition_method_;
18546  };
18547 
18548  namespace trie
18549  {
18550  template <typename KeyIterator, typename ValueType>
18551  class prefix
18552  {
18553 
18554  template <typename Iterator,
18555  typename Value,
18556  typename KeyValue = typename std::iterator_traits<Iterator>::value_type>
18557  struct node
18558  {
18559  public:
18560 
18561  typedef KeyValue key_value_t;
18562  typedef Value value_t;
18563 
18564  typedef node<Iterator,Value,KeyValue> node_t;
18565  typedef node_t* node_ptr;
18566  typedef const node_ptr const_node_ptr;
18567 
18568  typedef std::vector<node_ptr> node_list_t;
18569  typedef typename node_list_t::const_iterator node_list_iterator;
18570 
18571  explicit node(const key_value_t& key_value)
18572  : key_value_(key_value),
18573  value_holder_(false)
18574  {}
18575 
18576  node(const key_value_t& key_value, const value_t& v)
18577  : key_value_(key_value),
18578  value_holder_(true),
18579  value_(v)
18580  {}
18581 
18582  ~node()
18583  {
18584  if (!node_list_.empty())
18585  {
18586  node_list_iterator itr = node_list_.begin();
18587  node_list_iterator end = node_list_.end();
18588  while (end != itr)
18589  {
18590  delete (*itr);
18591  ++itr;
18592  }
18593  }
18594  }
18595 
18596  inline node_ptr get_node(const key_value_t& key_value)
18597  {
18598  if (node_list_.empty())
18599  return 0;
18600  node_list_iterator itr = node_list_.begin();
18601  const node_list_iterator end = node_list_.end();
18602  while (end != itr)
18603  {
18604  if (key_value == (*itr)->key_value_)
18605  return (*itr);
18606  else
18607  ++itr;
18608  }
18609  return 0;
18610  }
18611 
18612  inline void assign_value(const value_t& v)
18613  {
18614  value_ = v;
18615  value_holder_ = true;
18616  }
18617 
18618  inline void add_node(node_ptr n)
18619  {
18620  node_list_.push_back(n);
18621  }
18622 
18623  inline bool value_holder() const
18624  {
18625  return value_holder_;
18626  }
18627 
18628  inline const value_t& value() const
18629  {
18630  return value_;
18631  }
18632 
18633  inline const key_value_t& key() const
18634  {
18635  return key_value_;
18636  }
18637 
18638  private:
18639 
18640  node(const node_t& n);
18641  node_t& operator=(const node_t& n);
18642 
18643  key_value_t key_value_;
18644  bool value_holder_;
18645  value_t value_;
18646  node_list_t node_list_;
18647  };
18648 
18649  public:
18650 
18651  //typedef KeyIterator key_iterator_t;
18652  typedef typename std::iterator_traits<KeyIterator>::value_type key_value_t;
18653  typedef ValueType value_t;
18654 
18655  typedef node<KeyIterator,value_t> node_t;
18656  typedef node_t* node_ptr;
18657 
18659  : head_(0)
18660  {}
18661 
18662  template <typename key_iterator_t>
18663  inline void insert(const key_iterator_t begin,
18664  const key_iterator_t end,
18665  const value_t& v)
18666  {
18667  if (0 == std::distance(begin,end))
18668  return;
18669 
18670  key_iterator_t itr = begin;
18671  key_value_t key = (*itr);
18672  node_ptr parent = 0;
18673  node_ptr next_node = 0;
18674  node_ptr n = head_ = ((0 == head_) ? new node_t(*itr) : head_);
18675 
18676  while (end != itr)
18677  {
18678  key = (*itr);
18679  if (0 == (next_node = n->get_node(key)))
18680  {
18681  n->add_node(next_node = new node_t(key));
18682  }
18683  parent = n;
18684  n = next_node;
18685  ++itr;
18686  }
18687 
18688  parent->assign_value(v);
18689  }
18690 
18691  template <typename key_iterator_t>
18692  inline bool find(const key_iterator_t begin,
18693  const key_iterator_t end,
18694  value_t& v) const
18695  {
18696  if ((0 == head_) || (0 == std::distance(begin,end)))
18697  return false;
18698  key_iterator_t itr = begin;
18699  node_ptr parent = head_;
18700  node_ptr n = head_;
18701  while (end != itr)
18702  {
18703  node_ptr next_node = n->get_node(*itr);
18704  if (0 == next_node)
18705  return false;
18706  parent = n;
18707  n = next_node;
18708  ++itr;
18709  }
18710  if (!parent->value_holder())
18711  return false;
18712  v = parent->value();
18713  return true;
18714  }
18715 
18716  template <typename key_iterator_t>
18717  inline bool find_prefix(const key_iterator_t begin, const key_iterator_t end) const
18718  {
18719  if ((0 == head_) || (0 == std::distance(begin,end)))
18720  return false;
18721 
18722  key_iterator_t itr = begin;
18723  node_ptr n = head_;
18724 
18725  while (end != itr)
18726  {
18727  if (0 == (n = n->get_node(*itr)))
18728  return false;
18729  ++itr;
18730  }
18731 
18732  return true;
18733  }
18734 
18736  {
18737  delete head_;
18738  }
18739 
18740  private:
18741 
18742  node_ptr head_;
18743  };
18744 
18745  template <typename Value>
18747  const std::string& key,
18748  const Value& value = Value(0))
18749  {
18750  trie.insert(key.begin(),key.end(),value);
18751  }
18752 
18753  template <typename Value>
18755  const char* key,
18756  const Value& value = Value(0))
18757  {
18758  insert_into_trie(trie,std::string(key),value);
18759  }
18760 
18761  template <typename Value>
18763  const std::string& key,
18764  Value& v)
18765  {
18766  return trie.find(key.begin(),key.end(),v);
18767  }
18768 
18769  template <typename Value>
18771  const char* key,
18772  Value& v)
18773  {
18774  return find_prefix(trie,std::string(key),v);
18775  }
18776 
18777  template <typename Value>
18779  const std::string& key)
18780  {
18781  return trie.find_prefix(key.begin(),key.end());
18782  }
18783 
18784  template <typename Value>
18786  const char* key)
18787  {
18788  return find_prefix(trie,std::string(key));
18789  }
18790 
18791  } // namespace trie
18792 
18793  template <typename ValueType, typename KeyIterator = std::string::const_iterator>
18795  {
18802  };
18803 
18804  namespace bloom
18805  {
18806 
18807  static const std::size_t bits_per_char = 0x08; // 8 bits in 1 char(unsigned)
18808  static const unsigned char bit_mask[bits_per_char] = {
18809  0x01, //00000001
18810  0x02, //00000010
18811  0x04, //00000100
18812  0x08, //00001000
18813  0x10, //00010000
18814  0x20, //00100000
18815  0x40, //01000000
18816  0x80 //10000000
18817  };
18818 
18820  {
18821  public:
18822 
18824  : minimum_size(1),
18825  maximum_size(std::numeric_limits<unsigned long long int>::max()),
18826  minimum_number_of_hashes(1),
18827  maximum_number_of_hashes(std::numeric_limits<unsigned int>::max()),
18828  projected_element_count(10000),
18829  false_positive_probability(1.0 / projected_element_count),
18830  random_seed(0xA5A5A5A55A5A5A5AULL)
18831  {}
18832 
18833  virtual ~parameters()
18834  {}
18835 
18836  inline bool operator!()
18837  {
18838  return (minimum_size > maximum_size) ||
18839  (minimum_number_of_hashes > maximum_number_of_hashes) ||
18840  (minimum_number_of_hashes < 1) ||
18841  (0 == maximum_number_of_hashes) ||
18842  (0 == projected_element_count) ||
18843  (false_positive_probability < 0.0) ||
18844  (std::numeric_limits<double>::infinity() == std::abs(false_positive_probability)) ||
18845  (0 == random_seed) ||
18846  (0xFFFFFFFFFFFFFFFFULL == random_seed);
18847  }
18848 
18849  //Allowed min/max size of the bloom filter in bits
18850  unsigned long long int minimum_size;
18851  unsigned long long int maximum_size;
18852 
18853  //Allowed min/max number of hash functions
18856 
18857  //The approximate number of elements to be inserted
18858  //into the bloom filter, should be within one order
18859  //of magnitude. The default is 10000.
18860  unsigned long long int projected_element_count;
18861 
18862  //The approximate false positive probability expected
18863  //from the bloom filter. The default is the reciprocal
18864  //of the projected_element_count.
18866 
18867  unsigned long long int random_seed;
18868 
18869  inline bool operator()(strtk::binary::reader& reader)
18870  {
18871  return reader(minimum_size) &&
18872  reader(maximum_size) &&
18873  reader(minimum_number_of_hashes) &&
18874  reader(maximum_number_of_hashes) &&
18875  reader(projected_element_count) &&
18876  reader(false_positive_probability) &&
18877  reader(random_seed);
18878  }
18879 
18880  inline bool operator()(strtk::binary::writer& writer)
18881  {
18882  return writer(minimum_size) &&
18883  writer(maximum_size) &&
18884  writer(minimum_number_of_hashes) &&
18885  writer(maximum_number_of_hashes) &&
18886  writer(projected_element_count) &&
18887  writer(false_positive_probability) &&
18888  writer(random_seed);
18889  }
18890 
18892  {
18894  : number_of_hashes(0),
18895  table_size(0)
18896  {}
18897 
18898  unsigned int number_of_hashes;
18899  unsigned long long int table_size;
18900  };
18901 
18903 
18905  {
18906  /*
18907  Note:
18908  The following will attempt to find the number of hash functions
18909  and minimum amount of storage bits required to construct a bloom
18910  filter consistent with the user defined false positive probability
18911  and estimated element insertion count.
18912  */
18913 
18914  if (!(*this))
18915  return false;
18916 
18917  double min_m = std::numeric_limits<double>::infinity();
18918  double min_k = 0.0;
18919  double curr_m = 0.0;
18920  double k = 1.0;
18921 
18922  while (k < 1000.0)
18923  {
18924  double numerator = -k * projected_element_count;
18925  double denominator = std::log(1.0 - std::pow(false_positive_probability, 1.0 / k));
18926  curr_m = numerator / denominator;
18927  if (curr_m < min_m)
18928  {
18929  min_m = curr_m;
18930  min_k = k;
18931  }
18932  k += 1.0;
18933  }
18934 
18935  optimal_parameters_t& optp = optimal_parameters;
18936 
18937  optp.number_of_hashes = static_cast<unsigned int>(min_k);
18938  optp.table_size = static_cast<unsigned long long int>(min_m);
18939  optp.table_size += (((optp.table_size % bits_per_char) != 0) ? (bits_per_char - (optp.table_size % bits_per_char)) : 0);
18940 
18941  if (optp.number_of_hashes < minimum_number_of_hashes)
18942  optp.number_of_hashes = minimum_number_of_hashes;
18943  else if (optp.number_of_hashes > maximum_number_of_hashes)
18944  optp.number_of_hashes = maximum_number_of_hashes;
18945 
18946  if (optp.table_size < minimum_size)
18947  optp.table_size = minimum_size;
18948  else if (optp.table_size > maximum_size)
18949  optp.table_size = maximum_size;
18950 
18951  return true;
18952  }
18953 
18954  };
18955 
18956  class filter
18957  {
18958  protected:
18959 
18960  typedef unsigned int bloom_type;
18961  typedef unsigned char cell_type;
18962 
18963  public:
18964 
18966  : bit_table_(0),
18967  salt_count_(0),
18968  table_size_(0),
18969  raw_table_size_(0),
18970  projected_element_count_(0),
18971  inserted_element_count_(0),
18972  random_seed_(0),
18973  desired_false_positive_probability_(0.0)
18974  {}
18975 
18976  filter(const parameters& p)
18977  : bit_table_(0),
18978  projected_element_count_(p.projected_element_count),
18979  inserted_element_count_(0),
18980  random_seed_((p.random_seed * 0xA5A5A5A5) + 1),
18981  desired_false_positive_probability_(p.false_positive_probability)
18982  {
18983  salt_count_ = p.optimal_parameters.number_of_hashes;
18984  table_size_ = p.optimal_parameters.table_size;
18985  generate_unique_salt();
18986  raw_table_size_ = table_size_ / bits_per_char;
18987  bit_table_ = new cell_type[static_cast<std::size_t>(raw_table_size_)];
18988  std::fill_n(bit_table_,raw_table_size_,0x00);
18989  }
18990 
18992  {
18993  this->operator=(filter);
18994  }
18995 
18996  inline bool operator == (const filter& f) const
18997  {
18998  if (this != &f)
18999  {
19000  return
19001  (salt_count_ == f.salt_count_) &&
19002  (table_size_ == f.table_size_) &&
19003  (raw_table_size_ == f.raw_table_size_) &&
19004  (projected_element_count_ == f.projected_element_count_) &&
19005  (inserted_element_count_ == f.inserted_element_count_) &&
19006  (random_seed_ == f.random_seed_) &&
19007  (desired_false_positive_probability_ == f.desired_false_positive_probability_) &&
19008  (salt_ == f.salt_) &&
19009  std::equal(f.bit_table_,f.bit_table_ + raw_table_size_,bit_table_);
19010  }
19011  else
19012  return true;
19013  }
19014 
19015  inline bool operator != (const filter& f) const
19016  {
19017  return !operator==(f);
19018  }
19019 
19020  inline filter& operator = (const filter& f)
19021  {
19022  if (this != &f)
19023  {
19024  salt_count_ = f.salt_count_;
19025  table_size_ = f.table_size_;
19026  raw_table_size_ = f.raw_table_size_;
19027  projected_element_count_ = f.projected_element_count_;
19028  inserted_element_count_ = f.inserted_element_count_;
19029  random_seed_ = f.random_seed_;
19030  desired_false_positive_probability_ = f.desired_false_positive_probability_;
19031  delete[] bit_table_;
19032  bit_table_ = new cell_type[static_cast<std::size_t>(raw_table_size_)];
19033  std::copy(f.bit_table_,f.bit_table_ + raw_table_size_,bit_table_);
19034  salt_ = f.salt_;
19035  }
19036  return *this;
19037  }
19038 
19039  virtual ~filter()
19040  {
19041  delete[] bit_table_;
19042  }
19043 
19044  inline bool operator!() const
19045  {
19046  return (0 == table_size_);
19047  }
19048 
19049  inline void clear()
19050  {
19051  std::fill_n(bit_table_,raw_table_size_,0x00);
19052  inserted_element_count_ = 0;
19053  }
19054 
19055  inline void insert(const unsigned char* key_begin, const std::size_t& length)
19056  {
19057  std::size_t bit_index = 0;
19058  std::size_t bit = 0;
19059  for (std::size_t i = 0; i < salt_.size(); ++i)
19060  {
19061  compute_indices(hash_ap(key_begin,length,salt_[i]),bit_index,bit);
19062  bit_table_[bit_index / bits_per_char] |= bit_mask[bit];
19063  }
19064  ++inserted_element_count_;
19065  }
19066 
19067  template <typename T>
19068  inline void insert(const T& t)
19069  {
19070  // Note: T must be a C++ POD type.
19071  insert(reinterpret_cast<const unsigned char*>(&t),sizeof(T));
19072  }
19073 
19074  inline void insert(const std::string& key)
19075  {
19076  insert(reinterpret_cast<const unsigned char*>(key.data()),key.size());
19077  }
19078 
19079  inline void insert(const char* data, const std::size_t& length)
19080  {
19081  insert(reinterpret_cast<const unsigned char*>(data),length);
19082  }
19083 
19084  template <typename InputIterator>
19085  inline void insert(const InputIterator begin, const InputIterator end)
19086  {
19087  InputIterator itr = begin;
19088  while (end != itr)
19089  {
19090  insert(*(itr++));
19091  }
19092  }
19093 
19094  inline virtual bool contains(const unsigned char* key_begin, const std::size_t length) const
19095  {
19096  std::size_t bit_index = 0;
19097  std::size_t bit = 0;
19098  for (std::size_t i = 0; i < salt_.size(); ++i)
19099  {
19100  compute_indices(hash_ap(key_begin,length,salt_[i]),bit_index,bit);
19101  if ((bit_table_[bit_index / bits_per_char] & bit_mask[bit]) != bit_mask[bit])
19102  {
19103  return false;
19104  }
19105  }
19106  return true;
19107  }
19108 
19109  template <typename T>
19110  inline bool contains(const T& t) const
19111  {
19112  return contains(reinterpret_cast<const unsigned char*>(&t),static_cast<std::size_t>(sizeof(T)));
19113  }
19114 
19115  inline bool contains(const std::string& key) const
19116  {
19117  return contains(reinterpret_cast<const unsigned char*>(key.data()),key.size());
19118  }
19119 
19120  inline bool contains(const char* data, const std::size_t& length) const
19121  {
19122  return contains(reinterpret_cast<const unsigned char*>(data),length);
19123  }
19124 
19125  template <typename InputIterator>
19126  inline InputIterator contains_all(const InputIterator begin, const InputIterator end) const
19127  {
19128  InputIterator itr = begin;
19129  while (end != itr)
19130  {
19131  if (!contains(*itr))
19132  {
19133  return itr;
19134  }
19135  ++itr;
19136  }
19137  return end;
19138  }
19139 
19140  template <typename InputIterator>
19141  inline InputIterator contains_none(const InputIterator begin, const InputIterator end) const
19142  {
19143  InputIterator itr = begin;
19144  while (end != itr)
19145  {
19146  if (contains(*itr))
19147  {
19148  return itr;
19149  }
19150  ++itr;
19151  }
19152  return end;
19153  }
19154 
19155  inline virtual unsigned long long int size() const
19156  {
19157  return table_size_;
19158  }
19159 
19160  inline std::size_t element_count() const
19161  {
19162  return inserted_element_count_;
19163  }
19164 
19165  inline double effective_fpp() const
19166  {
19167  /*
19168  Note:
19169  The effective false positive probability is calculated using the
19170  designated table size and hash function count in conjunction with
19171  the current number of inserted elements - not the user defined
19172  predicated/expected number of inserted elements.
19173  */
19174  return std::pow(1.0 - std::exp(-1.0 * salt_.size() * inserted_element_count_ / size()), 1.0 * salt_.size());
19175  }
19176 
19177  inline filter& operator &= (const filter& f)
19178  {
19179  /* intersection */
19180  if (
19181  (salt_count_ == f.salt_count_) &&
19182  (table_size_ == f.table_size_) &&
19183  (random_seed_ == f.random_seed_)
19184  )
19185  {
19186  for (std::size_t i = 0; i < raw_table_size_; ++i)
19187  {
19188  bit_table_[i] &= f.bit_table_[i];
19189  }
19190  }
19191  return *this;
19192  }
19193 
19194  inline filter& operator |= (const filter& f)
19195  {
19196  /* union */
19197  if (
19198  (salt_count_ == f.salt_count_) &&
19199  (table_size_ == f.table_size_) &&
19200  (random_seed_ == f.random_seed_)
19201  )
19202  {
19203  for (std::size_t i = 0; i < raw_table_size_; ++i)
19204  {
19205  bit_table_[i] |= f.bit_table_[i];
19206  }
19207  }
19208  return *this;
19209  }
19210 
19211  inline filter& operator ^= (const filter& f)
19212  {
19213  /* difference */
19214  if (
19215  (salt_count_ == f.salt_count_) &&
19216  (table_size_ == f.table_size_) &&
19217  (random_seed_ == f.random_seed_)
19218  )
19219  {
19220  for (std::size_t i = 0; i < raw_table_size_; ++i)
19221  {
19222  bit_table_[i] ^= f.bit_table_[i];
19223  }
19224  }
19225  return *this;
19226  }
19227 
19228  inline const cell_type* table() const
19229  {
19230  return bit_table_;
19231  }
19232 
19233  inline bool write_to_file(const std::string& file_name) const
19234  {
19235  if (0 == table_size_)
19236  return false;
19237  const std::size_t buffer_size = sizeof( salt_count_) +
19238  sizeof( table_size_) +
19239  sizeof( raw_table_size_) +
19240  sizeof( projected_element_count_) +
19241  sizeof( inserted_element_count_) +
19242  sizeof( random_seed_) +
19243  sizeof(desired_false_positive_probability_) +
19244  salt_count_ * sizeof( bloom_type) +
19245  static_cast<std::size_t>(raw_table_size_) *
19246  sizeof(cell_type) +
19247  64; // handle array sizes etc.
19248  std::ofstream ostream(file_name.c_str(),std::ios::binary);
19249  if (!ostream)
19250  return false;
19251  unsigned char* buffer = new unsigned char[buffer_size];
19252  strtk::binary::writer writer(buffer,buffer_size);
19253  writer.reset(true);
19254  bool result = writer(salt_count_) &&
19255  writer(table_size_) &&
19256  writer(raw_table_size_) &&
19257  writer(projected_element_count_) &&
19258  writer(inserted_element_count_) &&
19259  writer(random_seed_) &&
19260  writer(desired_false_positive_probability_) &&
19261  writer(salt_) &&
19262  writer(bit_table_,raw_table_size_);
19263  if (result)
19264  {
19265  writer(ostream);
19266  }
19267  ostream.close();
19268  delete[] buffer;
19269  return result;
19270  }
19271 
19272  inline bool read_from_file(const std::string& file_name)
19273  {
19274  std::ifstream istream(file_name.c_str(),std::ios::binary);
19275  if (!istream)
19276  return false;
19277  salt_count_ = 0;
19278  table_size_ = 0;
19279  raw_table_size_ = 0;
19280  projected_element_count_ = 0;
19281  inserted_element_count_ = 0;
19282  random_seed_ = 0;
19283  desired_false_positive_probability_ = 0.0;
19284  salt_.clear();
19285  if (0 != bit_table_)
19286  delete [] bit_table_;
19287  bit_table_= 0;
19288  const std::size_t buffer_size = strtk::fileio::file_size(file_name);
19289  unsigned char* buffer = new unsigned char[buffer_size];
19290  strtk::binary::reader reader(buffer,buffer_size);
19291  reader.reset(true);
19292  reader(istream,buffer_size);
19293  istream.close();
19294  bool result = reader(salt_count_) &&
19295  reader(table_size_) &&
19296  reader(raw_table_size_) &&
19297  reader(projected_element_count_) &&
19298  reader(inserted_element_count_) &&
19299  reader(random_seed_) &&
19300  reader(desired_false_positive_probability_) &&
19301  reader(salt_) &&
19302  reader(bit_table_,raw_table_size_);
19303  delete[] buffer;
19304  return result;
19305  }
19306 
19307  inline std::size_t hash_count()
19308  {
19309  return salt_.size();
19310  }
19311 
19312  protected:
19313 
19314  inline virtual void compute_indices(const bloom_type& hash, std::size_t& bit_index, std::size_t& bit) const
19315  {
19316  bit_index = static_cast<std::size_t>(hash % table_size_);
19317  bit = bit_index % bits_per_char;
19318  }
19319 
19321  {
19322  /*
19323  Note:
19324  A distinct hash function need not be implementation-wise
19325  distinct. In the current implementation "seeding" a common
19326  hash function with different values seems to be adequate.
19327  */
19328  const unsigned int predef_salt_count = 128;
19329  static const bloom_type predef_salt[predef_salt_count] =
19330  {
19331  0xAAAAAAAA, 0x55555555, 0x33333333, 0xCCCCCCCC,
19332  0x66666666, 0x99999999, 0xB5B5B5B5, 0x4B4B4B4B,
19333  0xAA55AA55, 0x55335533, 0x33CC33CC, 0xCC66CC66,
19334  0x66996699, 0x99B599B5, 0xB54BB54B, 0x4BAA4BAA,
19335  0xAA33AA33, 0x55CC55CC, 0x33663366, 0xCC99CC99,
19336  0x66B566B5, 0x994B994B, 0xB5AAB5AA, 0xAAAAAA33,
19337  0x555555CC, 0x33333366, 0xCCCCCC99, 0x666666B5,
19338  0x9999994B, 0xB5B5B5AA, 0xFFFFFFFF, 0xFFFF0000,
19339  0xB823D5EB, 0xC1191CDF, 0xF623AEB3, 0xDB58499F,
19340  0xC8D42E70, 0xB173F616, 0xA91A5967, 0xDA427D63,
19341  0xB1E8A2EA, 0xF6C0D155, 0x4909FEA3, 0xA68CC6A7,
19342  0xC395E782, 0xA26057EB, 0x0CD5DA28, 0x467C5492,
19343  0xF15E6982, 0x61C6FAD3, 0x9615E352, 0x6E9E355A,
19344  0x689B563E, 0x0C9831A8, 0x6753C18B, 0xA622689B,
19345  0x8CA63C47, 0x42CC2884, 0x8E89919B, 0x6EDBD7D3,
19346  0x15B6796C, 0x1D6FDFE4, 0x63FF9092, 0xE7401432,
19347  0xEFFE9412, 0xAEAEDF79, 0x9F245A31, 0x83C136FC,
19348  0xC3DA4A8C, 0xA5112C8C, 0x5271F491, 0x9A948DAB,
19349  0xCEE59A8D, 0xB5F525AB, 0x59D13217, 0x24E7C331,
19350  0x697C2103, 0x84B0A460, 0x86156DA9, 0xAEF2AC68,
19351  0x23243DA5, 0x3F649643, 0x5FA495A8, 0x67710DF8,
19352  0x9A6C499E, 0xDCFB0227, 0x46A43433, 0x1832B07A,
19353  0xC46AFF3C, 0xB9C8FFF0, 0xC9500467, 0x34431BDF,
19354  0xB652432B, 0xE367F12B, 0x427F4C1B, 0x224C006E,
19355  0x2E7E5A89, 0x96F99AA5, 0x0BEB452A, 0x2FD87C39,
19356  0x74B2E1FB, 0x222EFD24, 0xF357F60C, 0x440FCB1E,
19357  0x8BBE030F, 0x6704DC29, 0x1144D12F, 0x948B1355,
19358  0x6D8FD7E9, 0x1C11A014, 0xADD1592F, 0xFB3C712E,
19359  0xFC77642F, 0xF9C4CE8C, 0x31312FB9, 0x08B0DD79,
19360  0x318FA6E7, 0xC040D23D, 0xC0589AA7, 0x0CA5C075,
19361  0xF874B172, 0x0CF914D5, 0x784D3280, 0x4E8CFEBC,
19362  0xC569F575, 0xCDB2A091, 0x2CC016B4, 0x5C5F4421
19363  };
19364 
19365  if (salt_count_ <= predef_salt_count)
19366  {
19367  std::copy(predef_salt,
19368  predef_salt + salt_count_,
19369  std::back_inserter(salt_));
19370  for (unsigned int i = 0; i < salt_.size(); ++i)
19371  {
19372  /*
19373  Note:
19374  This is done to integrate the user defined random seed,
19375  so as to allow for the generation of unique bloom filter
19376  instances.
19377  */
19378  salt_[i] = salt_[i] * salt_[(i + 3) % salt_.size()] + static_cast<bloom_type>(random_seed_);
19379  }
19380  }
19381  else
19382  {
19383  std::copy(predef_salt,predef_salt + predef_salt_count,std::back_inserter(salt_));
19384  srand(static_cast<unsigned int>(random_seed_));
19385  while (salt_.size() < salt_count_)
19386  {
19387  bloom_type current_salt = static_cast<bloom_type>(rand()) * static_cast<bloom_type>(rand());
19388  if (0 == current_salt) continue;
19389  if (salt_.end() == std::find(salt_.begin(), salt_.end(), current_salt))
19390  {
19391  salt_.push_back(current_salt);
19392  }
19393  }
19394  }
19395  }
19396 
19397  inline bloom_type hash_ap(const unsigned char* begin, std::size_t remaining_length, bloom_type hash) const
19398  {
19399  const unsigned char* itr = begin;
19400  unsigned int loop = 0;
19401  while (remaining_length >= 8)
19402  {
19403  const unsigned int& i1 = *(reinterpret_cast<const unsigned int*>(itr)); itr += sizeof(unsigned int);
19404  const unsigned int& i2 = *(reinterpret_cast<const unsigned int*>(itr)); itr += sizeof(unsigned int);
19405  hash ^= (hash << 7) ^ i1 * (hash >> 3) ^
19406  (~((hash << 11) + (i2 ^ (hash >> 5))));
19407  remaining_length -= 8;
19408  }
19409  while (remaining_length >= 4)
19410  {
19411  const unsigned int& i = *(reinterpret_cast<const unsigned int*>(itr));
19412  if (loop & 0x01)
19413  hash ^= (hash << 7) ^ i * (hash >> 3);
19414  else
19415  hash ^= (~((hash << 11) + (i ^ (hash >> 5))));
19416  ++loop;
19417  remaining_length -= 4;
19418  itr += sizeof(unsigned int);
19419  }
19420  while (remaining_length >= 2)
19421  {
19422  const unsigned short& i = *(reinterpret_cast<const unsigned short*>(itr));
19423  if (loop & 0x01)
19424  hash ^= (hash << 7) ^ i * (hash >> 3);
19425  else
19426  hash ^= (~((hash << 11) + (i ^ (hash >> 5))));
19427  ++loop;
19428  remaining_length -= 2;
19429  itr += sizeof(unsigned short);
19430  }
19431  if (remaining_length)
19432  hash += ((*itr) ^ (hash * 0x5A5A5A5A));
19433  else if (loop < 2)
19434  hash += ((hash + 1) * 0x5A5A5A5A);
19435  return hash;
19436  }
19437 
19438  std::vector<bloom_type> salt_;
19439  unsigned char* bit_table_;
19440  unsigned int salt_count_;
19441  unsigned long long int table_size_;
19442  unsigned long long int raw_table_size_;
19443  unsigned long long int projected_element_count_;
19445  unsigned long long int random_seed_;
19447  };
19448 
19449  inline filter operator & (const filter& a, const filter& b)
19450  {
19451  filter result = a;
19452  result &= b;
19453  return result;
19454  }
19455 
19456  inline filter operator | (const filter& a, const filter& b)
19457  {
19458  filter result = a;
19459  result |= b;
19460  return result;
19461  }
19462 
19463  inline filter operator ^ (const filter& a, const filter& b)
19464  {
19465  filter result = a;
19466  result ^= b;
19467  return result;
19468  }
19469 
19471  {
19472  public:
19473 
19475  : filter(p)
19476  {
19477  size_list.push_back(table_size_);
19478  }
19479 
19480  inline virtual unsigned long long int size() const
19481  {
19482  return size_list.back();
19483  }
19484 
19485  inline bool compress(const double& percentage)
19486  {
19487  if ((0.0 >= percentage) || (percentage >= 100.0))
19488  {
19489  return false;
19490  }
19491 
19492  unsigned long long int original_table_size = size_list.back();
19493  unsigned long long int new_table_size = static_cast<unsigned long long int>((size_list.back() * (1.0 - (percentage / 100.0))));
19494  new_table_size -= (((new_table_size % bits_per_char) != 0) ? (new_table_size % bits_per_char) : 0);
19495 
19496  if ((bits_per_char > new_table_size) || (new_table_size >= original_table_size))
19497  {
19498  return false;
19499  }
19500 
19501  desired_false_positive_probability_ = effective_fpp();
19502  cell_type* tmp = new cell_type[static_cast<std::size_t>(new_table_size / bits_per_char)];
19503  std::copy(bit_table_, bit_table_ + (new_table_size / bits_per_char), tmp);
19504  cell_type* itr = bit_table_ + (new_table_size / bits_per_char);
19505  cell_type* end = bit_table_ + (original_table_size / bits_per_char);
19506  cell_type* itr_tmp = tmp;
19507 
19508  while (end != itr)
19509  {
19510  *(itr_tmp++) |= (*itr++);
19511  }
19512 
19513  delete[] bit_table_;
19514  bit_table_ = tmp;
19515  size_list.push_back(new_table_size);
19516 
19517  return true;
19518  }
19519 
19520  private:
19521 
19522  inline virtual void compute_indices(const bloom_type& hash, std::size_t& bit_index, std::size_t& bit) const
19523  {
19524  bit_index = hash;
19525  for (std::size_t i = 0; i < size_list.size(); ++i)
19526  {
19527  bit_index %= size_list[i];
19528  }
19529  bit = bit_index % bits_per_char;
19530  }
19531 
19532  std::vector<unsigned long long int> size_list;
19533  };
19534 
19535  }
19536 
19537  namespace details
19538  {
19539 
19540  inline void compute_pod_hash(const char data[], unsigned int& hash)
19541  {
19542  hash ^= ((hash << 7) ^ data[0] * (hash >> 3));
19543  hash ^= ~((hash << 11) + (data[1] ^ (hash >> 5)));
19544  }
19545 
19546  inline void compute_pod_hash(const unsigned char data[], unsigned int& hash)
19547  {
19548  hash ^= ((hash << 7) ^ data[0] * (hash >> 3));
19549  hash ^= ~((hash << 11) + (data[1] ^ (hash >> 5)));
19550  }
19551 
19552  inline void compute_pod_hash(const int& data, unsigned int& hash)
19553  {
19554  const unsigned char* itr = reinterpret_cast<const unsigned char*>(&data);
19555  hash ^= ((hash << 7) ^ itr[0] * (hash >> 3));
19556  hash ^= ~((hash << 11) + (itr[1] ^ (hash >> 5)));
19557  hash ^= ((hash << 7) ^ itr[2] * (hash >> 3));
19558  hash ^= ~((hash << 11) + (itr[3] ^ (hash >> 5)));
19559  }
19560 
19561  inline void compute_pod_hash(const unsigned int& data, unsigned int& hash)
19562  {
19563  compute_pod_hash(static_cast<int>(data),hash);
19564  }
19565 
19566  inline void compute_pod_hash(const unsigned long long int& data, unsigned int& hash)
19567  {
19568  const unsigned char* itr = reinterpret_cast<const unsigned char*>(&data);
19569  hash ^= ((hash << 7) ^ itr[0] * (hash >> 3));
19570  hash ^= ~((hash << 11) + (itr[1] ^ (hash >> 5)));
19571  hash ^= ((hash << 7) ^ itr[2] * (hash >> 3));
19572  hash ^= ~((hash << 11) + (itr[3] ^ (hash >> 5)));
19573  hash ^= ((hash << 7) ^ itr[4] * (hash >> 3));
19574  hash ^= ~((hash << 11) + (itr[5] ^ (hash >> 5)));
19575  hash ^= ((hash << 7) ^ itr[6] * (hash >> 3));
19576  hash ^= ~((hash << 11) + (itr[7] ^ (hash >> 5)));
19577  }
19578 
19579  inline void compute_pod_hash(const double& data, unsigned int& hash)
19580  {
19581  const unsigned char* itr = reinterpret_cast<const unsigned char*>(&data);
19582  hash ^= ((hash << 7) ^ itr[0] * (hash >> 3));
19583  hash ^= ~((hash << 11) + (itr[1] ^ (hash >> 5)));
19584  hash ^= ((hash << 7) ^ itr[2] * (hash >> 3));
19585  hash ^= ~((hash << 11) + (itr[3] ^ (hash >> 5)));
19586  hash ^= ((hash << 7) ^ itr[4] * (hash >> 3));
19587  hash ^= ~((hash << 11) + (itr[5] ^ (hash >> 5)));
19588  hash ^= ((hash << 7) ^ itr[6] * (hash >> 3));
19589  hash ^= ~((hash << 11) + (itr[7] ^ (hash >> 5)));
19590  }
19591 
19592  template <std::size_t block_size, typename Iterator>
19593  inline void compute_block(Iterator itr, std::size_t& length, unsigned int& hash)
19594  {
19595  while (length >= block_size)
19596  {
19597  for (std::size_t i = 0; i < block_size; ++i, ++itr)
19598  {
19599  compute_pod_hash((*itr),hash);
19600  }
19601  length -= block_size;
19602  }
19603  }
19604 
19605  template <std::size_t block_size>
19606  inline void compute_block(unsigned char* itr, std::size_t& length, unsigned int& hash)
19607  {
19608  unsigned int local_hash = hash;
19609  while (length >= block_size)
19610  {
19611  for (std::size_t i = 0; i < block_size; ++i, ++itr)
19612  {
19613  compute_pod_hash((*itr),local_hash);
19614  }
19615  length -= block_size;
19616  }
19617  hash = local_hash;
19618  }
19619 
19620  template <std::size_t block_size>
19621  inline void compute_block(char* itr, std::size_t& length, unsigned int& hash)
19622  {
19623  compute_block<block_size>(reinterpret_cast<unsigned char*>(itr),length,hash);
19624  }
19625 
19626  static const unsigned int hash_seed = 0xAAAAAAAA;
19627 
19628  template <typename Iterator>
19629  inline void hash(const Iterator itr, std::size_t length, unsigned int& hash_value)
19630  {
19631  if (length >= 64) compute_block<64>(itr,length,hash_value);
19632  if (length >= 32) compute_block<32>(itr,length,hash_value);
19633  if (length >= 16) compute_block<16>(itr,length,hash_value);
19634  if (length >= 8) compute_block< 8>(itr,length,hash_value);
19635  if (length >= 4) compute_block< 4>(itr,length,hash_value);
19636  if (length >= 2) compute_block< 2>(itr,length,hash_value);
19637  if (length == 0) compute_block< 1>(itr,length,hash_value);
19638  }
19639 
19640  } // namespace details
19641 
19642  template <typename Iterator>
19643  inline unsigned int hash(const Iterator itr,
19644  std::size_t length,
19645  unsigned int seed = details::hash_seed)
19646  {
19647  unsigned int hash_value = seed;
19648  details::hash(itr,length,hash_value);
19649  return hash_value;
19650  }
19651 
19652  inline unsigned int hash(const std::string& s, unsigned int seed = details::hash_seed)
19653  {
19654  unsigned int hash_value = seed;
19655  return hash(s.begin(),s.size(),hash_value);
19656  }
19657 
19658  template <typename T,
19659  typename Allocator,
19660  template <typename,typename> class Sequence>
19661  inline unsigned int hash(const Sequence<T,Allocator>& sequence, unsigned int seed = details::hash_seed)
19662  {
19663  unsigned int hash_value = seed;
19664  return hash(sequence.begin(),sequence.size(),hash_value);
19665  }
19666 
19667  namespace util
19668  {
19669  template <typename T>
19671  {
19672  public:
19673 
19674  scoped_restore(T& t, const bool restore = true)
19675  : restore_(restore),
19676  reference_(t),
19677  copy_(t)
19678  {}
19679 
19681  {
19682  if (restore_)
19683  {
19684  reference_ = copy_;
19685  }
19686  }
19687 
19688  inline bool& restore()
19689  {
19690  return restore_;
19691  }
19692 
19693  private:
19694 
19695  bool restore_;
19696  T& reference_;
19697  T copy_;
19698  };
19699 
19700  template <typename T>
19702  {
19703  public:
19704 
19706  : initialised_(false)
19707  {}
19708 
19709  attribute(const T& t)
19710  {
19711  assign(t);
19712  prev_t_ = t;
19713  }
19714 
19715  inline attribute& operator=(const T& t)
19716  {
19717  prev_t_ = t_;
19718  assign(t);
19719  return *this;
19720  }
19721 
19722  inline bool operator==(const T& t)
19723  {
19724  return initialised_ && (t_ == t);
19725  }
19726 
19727  template <typename TConvertibleType>
19728  inline bool operator!=(const TConvertibleType& t)
19729  {
19730  return !(operator==(t));
19731  }
19732 
19733  inline T& operator()()
19734  {
19735  return t_;
19736  }
19737 
19738  inline const T& operator()() const
19739  {
19740  return t_;
19741  }
19742 
19743  inline operator T() const
19744  {
19745  return t_;
19746  }
19747 
19748  inline operator T()
19749  {
19750  return t_;
19751  }
19752 
19753  inline bool initialised() const
19754  {
19755  return initialised_;
19756  }
19757 
19758  inline bool& initialised()
19759  {
19760  return initialised_;
19761  }
19762 
19763  inline bool changed() const
19764  {
19765  return (initialised_ && (t_ != prev_t_));
19766  }
19767 
19768  inline const T& value() const
19769  {
19770  return t_;
19771  }
19772 
19773  inline T& value()
19774  {
19775  return t_;
19776  }
19777 
19778  inline const T& previous() const
19779  {
19780  return prev_t_;
19781  }
19782 
19783  inline T& previous()
19784  {
19785  return prev_t_;
19786  }
19787 
19788  private:
19789 
19790  inline void assign(const T& t)
19791  {
19792  t_ = t;
19793  initialised_ = true;
19794  }
19795 
19796  T t_;
19797  T prev_t_;
19798  bool initialised_;
19799  };
19800 
19801  inline bool operator==(const char* s, const attribute<std::string>& attrib)
19802  {
19803  return attrib.value() == s;
19804  }
19805 
19806  inline bool operator!=(const char* s, const attribute<std::string>& attrib)
19807  {
19808  return !(s == attrib.value());
19809  }
19810 
19811  template <typename T>
19812  static inline std::ostream& operator<<(std::ostream& os, const attribute<T>& attrib)
19813  {
19814  return (os << attrib.value());
19815  }
19816 
19818  {
19819  private:
19820 
19821  class function_holder_base
19822  {
19823  public:
19824 
19825  typedef const unsigned char* itr_type;
19826 
19827  virtual ~function_holder_base(){}
19828 
19829  virtual bool operator()(itr_type begin, itr_type end) const = 0;
19830 
19831  inline bool operator()(const char* begin, const char* end) const
19832  {
19833  return operator()(reinterpret_cast<itr_type>(begin),
19834  reinterpret_cast<itr_type>(end));
19835  }
19836 
19837  template <typename Iterator>
19838  inline bool operator()(const std::pair<Iterator,Iterator>& p) const
19839  {
19840  return operator()(p.first,p.second);
19841  }
19842  };
19843 
19844  template <typename Function>
19845  class function_holder : public function_holder_base
19846  {
19847  public:
19848 
19849  explicit function_holder(Function& f)
19850  : function_(&f)
19851  {}
19852 
19853  inline virtual bool operator()(itr_type begin, itr_type end) const
19854  {
19855  return (*function_)(begin,end);
19856  }
19857 
19858  private:
19859 
19860  Function* function_;
19861  };
19862 
19863  public:
19864 
19866  : function_holder_(0)
19867  {
19868  std::fill_n(function_holder_buffer_,sizeof(function_holder_buffer_),0x00);
19869  }
19870 
19871  template <typename Function>
19872  inline explicit semantic_action_impl(const Function& f)
19873  {
19874  std::fill_n(function_holder_buffer_,sizeof(function_holder_buffer_),0x00);
19875  assign(f);
19876  }
19877 
19878  inline bool operator!() const
19879  {
19880  return (0 == function_holder_);
19881  }
19882 
19883  inline bool operator==(const semantic_action_impl& sa) const
19884  {
19885  return (0 != function_holder_) &&
19886  (0 != sa.function_holder_) &&
19887  (function_holder_ == sa.function_holder_);
19888  }
19889 
19890  template <typename InputIterator>
19891  inline bool operator()(InputIterator begin, InputIterator end) const
19892  {
19893  if (0 != function_holder_)
19894  return (*function_holder_).operator()(begin,end);
19895  else
19896  return false;
19897  }
19898 
19899  template <typename InputIterator>
19900  inline bool operator()(const std::pair<InputIterator,InputIterator>& r) const
19901  {
19902  return operator()(r.first,r.second);
19903  }
19904 
19905  inline bool operator()(const std::string& s) const
19906  {
19907  return operator()(s.data(),s.data() + s.size());
19908  }
19909 
19910  template <typename Function>
19911  inline void assign(Function& f)
19912  {
19913  static const std::size_t type_size = sizeof(function_holder<Function>(f));
19914  function_holder_ = construct<Function,type_size <= function_holder_buffer_size>::type(f,function_holder_buffer_);
19915  }
19916 
19918  {
19919  return (*this);
19920  }
19921 
19922  private:
19923 
19924  typedef function_holder_base* function_holder_ptr;
19925 
19926  inline semantic_action_impl& operator=(const semantic_action_impl&);
19927 
19928  template <typename Function, bool b>
19929  struct construct
19930  {
19931  inline static function_holder_ptr type(Function&, unsigned char*)
19932  {
19933  return reinterpret_cast<function_holder_ptr>(0);
19934  }
19935  };
19936 
19937  template <typename Function>
19938  struct construct<Function,true>
19939  {
19940  inline static function_holder_ptr type(Function& f, unsigned char* buffer)
19941  {
19942  return new(buffer)function_holder<Function>(f);
19943  }
19944  };
19945 
19946  function_holder_ptr function_holder_;
19947  enum { function_holder_buffer_size = 64 };
19948  unsigned char function_holder_buffer_[function_holder_buffer_size];
19949  };
19950 
19951  template <typename Function>
19953  {
19954  return semantic_action_impl(f);
19955  }
19956 
19957  } // namespace util
19958 
19959  namespace details
19960  {
19961  #define strtk_register_attribute_type_tag(T)\
19962  template<> struct supported_conversion_to_type< strtk::util::attribute<T> >{ typedef attribute_type_tag type; };\
19963  template<> struct supported_conversion_from_type< strtk::util::attribute<T> > { typedef attribute_type_tag type; };
19964 
19966  strtk_register_attribute_type_tag(unsigned int)
19967  strtk_register_attribute_type_tag(unsigned long)
19968  strtk_register_attribute_type_tag(unsigned long long int)
19976  strtk_register_attribute_type_tag(unsigned char)
19980 
19981  template <typename Iterator, typename T>
19982  inline bool string_to_type_converter_impl(Iterator& itr, const Iterator end, strtk::util::attribute<T>& result, attribute_type_tag)
19983  {
19984  if (strtk::string_to_type_converter(itr,end,result.value()))
19985  {
19986  result.initialised() = true;
19987  return true;
19988  }
19989  else
19990  return false;
19991  }
19992 
19993  template <typename T>
19995  {
19996  if (!attrib.initialised())
19997  return false;
19998  return strtk::type_to_string(attrib.value(),result);
19999  }
20000 
20001  #undef strtk_register_attribute_type_tag
20002 
20005 
20006  template <typename Iterator>
20007  inline bool string_to_type_converter_impl(Iterator& itr, const Iterator end, strtk::util::semantic_action_impl& result, semantic_action_type_tag)
20008  {
20009  return result(itr,end);
20010  }
20011 
20013  {
20014  static std::string result_str = "semantic_action";
20015  result = result_str;
20016  return true;
20017  }
20018 
20019  } // namespace details
20020 
20021  namespace util
20022  {
20023  class value
20024  {
20025  private:
20026 
20027  class type_holder_base
20028  {
20029  public:
20030 
20031  typedef const unsigned char* itr_type;
20032 
20033  virtual ~type_holder_base(){}
20034 
20035  virtual bool operator()(itr_type begin, itr_type end) const = 0;
20036 
20037  virtual bool to_string(std::string& s) const = 0;
20038 
20039  inline bool operator()(const char* begin, const char* end) const
20040  {
20041  return operator()(reinterpret_cast<itr_type>(begin),
20042  reinterpret_cast<itr_type>(end));
20043  }
20044 
20045  template <typename Iterator>
20046  inline bool operator()(const std::pair<Iterator,Iterator>& p) const
20047  {
20048  return operator()(p.first,p.second);
20049  }
20050  };
20051 
20052  template <typename T>
20053  class type_holder : public type_holder_base
20054  {
20055  public:
20056 
20057  typedef T* type_ptr;
20058 
20059  explicit type_holder(T& t)
20060  : value_ptr_(&t)
20061  {}
20062 
20063  inline virtual bool operator()(itr_type begin, itr_type end) const
20064  {
20065  return strtk::string_to_type_converter(begin,end,(*value_ptr_));
20066  }
20067 
20068  inline virtual bool to_string(std::string& s) const
20069  {
20070  return strtk::type_to_string((*value_ptr_),s);
20071  }
20072 
20073  inline operator T() const
20074  {
20075  return (*value_ptr_);
20076  }
20077 
20078  private:
20079 
20080  type_ptr value_ptr_;
20081  };
20082 
20083  public:
20084 
20086  : type_holder_(0)
20087  {
20088  std::fill_n(type_holder_buffer_,sizeof(type_holder_buffer_),0x00);
20089  }
20090 
20091  template <typename T>
20092  inline explicit value(T& t)
20093  {
20094  std::fill_n(type_holder_buffer_,sizeof(type_holder_buffer_),0x00);
20095  assign(t);
20096  }
20097 
20098  inline bool operator!() const
20099  {
20100  return (0 == type_holder_);
20101  }
20102 
20103  inline bool operator==(const value& v) const
20104  {
20105  return (0 != type_holder_) &&
20106  (0 != v.type_holder_) &&
20107  (type_holder_ == v.type_holder_);
20108  }
20109 
20110  inline value& operator=(const value& v)
20111  {
20112  if (&v != this)
20113  {
20114  if (0 != v.type_holder_)
20115  {
20116  std::copy(v.type_holder_buffer_,
20117  v.type_holder_buffer_ + type_holder_buffer_size,
20118  type_holder_buffer_);
20119  type_holder_ = reinterpret_cast<type_holder_base*>(type_holder_buffer_);
20120  }
20121  }
20122  return *this;
20123  }
20124 
20125  template <typename InputIterator>
20126  inline bool operator()(InputIterator begin, InputIterator end) const
20127  {
20128  if (0 != type_holder_)
20129  return (*type_holder_).operator()(begin,end);
20130  else
20131  return false;
20132  }
20133 
20134  template <typename InputIterator>
20135  inline bool operator()(const std::pair<InputIterator,InputIterator>& r) const
20136  {
20137  return operator()(r.first,r.second);
20138  }
20139 
20140  inline bool operator()(const std::string& s) const
20141  {
20142  return operator()(s.data(),s.data() + s.size());
20143  }
20144 
20145  template <typename T>
20146  inline void assign(T& t)
20147  {
20148  static const std::size_t type_size = sizeof(type_holder<T>(t));
20149  type_holder_ = construct<T,type_size <= type_holder_buffer_size>::type(t,type_holder_buffer_);
20150  }
20151 
20152  inline bool to_string(std::string& s) const
20153  {
20154  if (0 != type_holder_)
20155  return (*type_holder_).to_string(s);
20156  else
20157  return false;
20158  }
20159 
20160  template <typename T>
20161  inline operator T() const
20162  {
20163  if (0 != type_holder_)
20164  return (*type_holder_);
20165  else
20166  return T();
20167  }
20168 
20169  private:
20170 
20171  typedef type_holder_base* type_holder_ptr;
20172 
20173  template <typename T, bool b>
20174  struct construct
20175  {
20176  inline static type_holder_ptr type(T&, unsigned char*)
20177  {
20178  return reinterpret_cast<type_holder_ptr>(0);
20179  }
20180  };
20181 
20182  template <typename T>
20183  struct construct<T,true>
20184  {
20185  inline static type_holder_ptr type(T& t, unsigned char* buffer)
20186  {
20187  return new(buffer)type_holder<T>(t);
20188  }
20189  };
20190 
20191  type_holder_ptr type_holder_;
20192  enum { type_holder_buffer_size = 2 * sizeof(type_holder<unsigned long long int>) };
20193  unsigned char type_holder_buffer_[type_holder_buffer_size];
20194  };
20195 
20196  template <typename Key,
20197  typename T,
20198  typename Comparator,
20199  typename MapAllocator,
20200  typename OutputIterator>
20201  inline void make_key_list(const std::map<Key,T,Comparator,MapAllocator>& map,
20202  OutputIterator out)
20203  {
20204  if (map.empty()) return;
20205  typedef typename std::map<Key,T,Comparator,MapAllocator> map_type;
20206  typename map_type::const_iterator itr = map.begin();
20207  typename map_type::const_iterator end = map.end();
20208  while (end != itr)
20209  {
20210  *out++ = (itr++)->first;
20211  }
20212  }
20213 
20214  template <typename Key,
20215  typename T,
20216  typename Comparator,
20217  typename MapAllocator,
20218  typename SetAllocator>
20219  inline void make_key_list(const std::map<Key,T,Comparator,MapAllocator>& map,
20220  std::set<Key,Comparator,SetAllocator>& set)
20221  {
20222  make_key_list(map,std::inserter(set,set.begin()));
20223  }
20224 
20225  template <typename Key,
20226  typename T,
20227  typename Comparator,
20228  typename MapAllocator,
20229  typename SetAllocator>
20230  inline void make_key_list(const std::map<Key,T,Comparator,MapAllocator>& map,
20231  std::multiset<Key,Comparator,SetAllocator>& multiset)
20232  {
20233  make_key_list(map,std::inserter(multiset,multiset.begin()));
20234  }
20235 
20236  template <typename Key,
20237  typename T,
20238  typename Comparator,
20239  typename MapAllocator,
20240  typename SequenceAllocator,
20241  template <typename,typename> class Sequence>
20242  inline void make_key_list(const std::map<Key,T,Comparator,MapAllocator>& map,
20243  Sequence<Key,SequenceAllocator>& sequence)
20244  {
20245  make_key_list(map,std::back_inserter(sequence));
20246  }
20247 
20248  template <typename Key,
20249  typename T,
20250  typename Comparator,
20251  typename MapAllocator,
20252  typename OutputIterator>
20253  inline void make_value_list(const std::multimap<Key,T,Comparator,MapAllocator>& map,
20254  const Key& key,
20255  OutputIterator out)
20256  {
20257  if (map.empty()) return;
20258  typedef typename std::multimap<Key,T,Comparator,MapAllocator> map_type;
20259  typename map_type::const_iterator itr = map.find(key);
20260  typename map_type::const_iterator end = map.end();
20261  while ((end != itr) && (key == itr->first))
20262  {
20263  *out++ = (itr++)->second;
20264  }
20265  }
20266 
20267  template <typename Key,
20268  typename T,
20269  typename Comparator,
20270  typename MapAllocator,
20271  typename SequenceAllocator,
20272  template <typename,typename> class Sequence>
20273  inline void make_value_list(const std::multimap<Key,T,Comparator,MapAllocator>& map,
20274  const Key& key,
20275  Sequence<T,SequenceAllocator>& sequence)
20276  {
20277  make_value_list(map,key,std::back_inserter(sequence));
20278  }
20279 
20280  template <typename T,
20281  typename Allocator,
20282  template <typename,typename> class Sequence>
20283  inline void delete_all(Sequence<T*,Allocator>& sequence)
20284  {
20285  typename Sequence<T*,Allocator>::iterator itr = sequence.begin();
20286  typename Sequence<T*,Allocator>::iterator end = sequence.end();
20287  while (end != itr)
20288  {
20289  delete (*itr);
20290  ++itr;
20291  }
20292  sequence.clear();
20293  }
20294 
20295  template <typename Key,
20296  typename T,
20297  typename Comparator,
20298  typename Allocator>
20299  inline void delete_all(std::map<Key,T*,Comparator,Allocator>& cont)
20300  {
20301  typename std::map<Key,T*,Comparator,Allocator>::iterator itr = cont.begin();
20302  typename std::map<Key,T*,Comparator,Allocator>::iterator end = cont.end();
20303  while (end != itr)
20304  {
20305  delete (*itr).second;
20306  ++itr;
20307  }
20308  cont.clear();
20309  }
20310 
20311  template <typename Key,
20312  typename T,
20313  typename Comparator,
20314  typename Allocator>
20315  inline void delete_all(std::multimap<Key,T*,Comparator,Allocator>& cont)
20316  {
20317  typename std::multimap<Key,T*,Comparator,Allocator>::iterator itr = cont.begin();
20318  typename std::multimap<Key,T*,Comparator,Allocator>::iterator end = cont.end();
20319  while (end != itr)
20320  {
20321  delete (*itr).second;
20322  ++itr;
20323  }
20324  cont.clear();
20325  }
20326 
20327  template <typename T,
20328  typename Comparator,
20329  typename Allocator>
20330  inline void delete_all(std::set<T*,Comparator,Allocator>& cont)
20331  {
20332  typename std::set<T*,Comparator,Allocator>::iterator itr = cont.begin();
20333  typename std::set<T*,Comparator,Allocator>::iterator end = cont.end();
20334  while (end != itr)
20335  {
20336  delete (*itr);
20337  ++itr;
20338  }
20339  cont.clear();
20340  }
20341 
20342  template <typename T,
20343  typename Comparator,
20344  typename Allocator>
20345  inline void delete_all(std::multiset<T*,Comparator,Allocator>& cont)
20346  {
20347  typename std::multiset<T*,Comparator,Allocator>::iterator itr = cont.begin();
20348  typename std::multiset<T*,Comparator,Allocator>::iterator end = cont.end();
20349  while (end != itr)
20350  {
20351  delete (*itr);
20352  ++itr;
20353  }
20354  cont.clear();
20355  }
20356 
20357  template <typename Predicate,
20358  typename T,
20359  typename Allocator,
20360  template <typename,typename> class Sequence>
20361  inline void delete_if(const Predicate& p,
20362  Sequence<T*,Allocator>& sequence)
20363  {
20364  typename Sequence<T*,Allocator>::iterator itr = sequence.begin();
20365  while (sequence.end() != itr)
20366  {
20367  if (p(*itr))
20368  {
20369  delete (*itr);
20370  itr = sequence.erase(itr);
20371  }
20372  else
20373  ++itr;
20374  }
20375  }
20376 
20377  template <typename Predicate,
20378  typename Key,
20379  typename T,
20380  typename Comparator,
20381  typename Allocator>
20382  inline void delete_if(const Predicate& p,
20383  std::map<Key,T*,Comparator,Allocator>& cont)
20384  {
20385  typename std::map<Key,T*,Comparator,Allocator>::iterator itr = cont.begin();
20386  while (cont.end() != itr)
20387  {
20388  if (p(*itr))
20389  {
20390  delete (*itr).second;
20391  itr = cont.erase(itr);
20392  }
20393  else
20394  ++itr;
20395  }
20396  }
20397 
20398  template <typename Predicate,
20399  typename Key,
20400  typename T,
20401  typename Comparator,
20402  typename Allocator>
20403  inline void delete_if(const Predicate& p,
20404  std::multimap<Key,T*,Comparator,Allocator>& cont)
20405  {
20406  typename std::multimap<Key,T*,Comparator,Allocator>::iterator itr = cont.begin();
20407  while (cont.end() != itr)
20408  {
20409  if (p(*itr))
20410  {
20411  delete (*itr).second;
20412  itr = cont.erase(itr);
20413  }
20414  else
20415  ++itr;
20416  }
20417  }
20418 
20419  template <typename Predicate,
20420  typename T,
20421  typename Comparator,
20422  typename Allocator>
20423  inline void delete_if(const Predicate& p,
20424  std::set<T*,Comparator,Allocator>& cont)
20425  {
20426  typename std::set<T*,Comparator,Allocator>::iterator itr = cont.begin();
20427  while (cont.end() != itr)
20428  {
20429  if (p(*itr))
20430  {
20431  delete (*itr).second;
20432  itr = cont.erase(itr);
20433  }
20434  else
20435  ++itr;
20436  }
20437  }
20438 
20439  template <typename Predicate,
20440  typename T,
20441  typename Comparator,
20442  typename Allocator>
20443  inline void delete_if(const Predicate& p,
20444  std::multiset<T*,Comparator,Allocator>& cont)
20445  {
20446  typename std::multiset<T*,Comparator,Allocator>::iterator itr = cont.begin();
20447  while (cont.end() != itr)
20448  {
20449  if (p(*itr))
20450  {
20451  delete (*itr).second;
20452  itr = cont.erase(itr);
20453  }
20454  else
20455  ++itr;
20456  }
20457  }
20458 
20459  template <typename T,
20460  typename Allocator,
20461  template <typename,typename> class Sequence>
20462  inline void push_back(Sequence<T,Allocator>& sequence,
20463  const T& v1, const T& v2, const T& v3, const T& v4,
20464  const T& v5, const T& v6, const T& v7, const T& v8,
20465  const T& v9, const T& v10, const T& v11)
20466  {
20467  sequence.push_back(v1); sequence.push_back(v2);
20468  sequence.push_back(v3); sequence.push_back(v4);
20469  sequence.push_back(v5); sequence.push_back(v6);
20470  sequence.push_back(v7); sequence.push_back(v8);
20471  sequence.push_back(v9); sequence.push_back(v10);
20472  sequence.push_back(v11);
20473  }
20474 
20475  template <typename T,
20476  typename Allocator,
20477  template <typename,typename> class Sequence>
20478  inline void push_back(Sequence<T,Allocator>& sequence,
20479  const T& v1, const T& v2, const T& v3, const T& v4,
20480  const T& v5, const T& v6, const T& v7, const T& v8,
20481  const T& v9, const T& v10)
20482  {
20483  sequence.push_back(v1); sequence.push_back(v2);
20484  sequence.push_back(v3); sequence.push_back(v4);
20485  sequence.push_back(v5); sequence.push_back(v6);
20486  sequence.push_back(v7); sequence.push_back(v8);
20487  sequence.push_back(v9); sequence.push_back(v10);
20488  }
20489 
20490  template <typename T,
20491  typename Allocator,
20492  template <typename,typename> class Sequence>
20493  inline void push_back(Sequence<T,Allocator>& sequence,
20494  const T& v1, const T& v2, const T& v3, const T& v4,
20495  const T& v5, const T& v6, const T& v7, const T& v8,
20496  const T& v9)
20497  {
20498  sequence.push_back(v1); sequence.push_back(v2);
20499  sequence.push_back(v3); sequence.push_back(v4);
20500  sequence.push_back(v5); sequence.push_back(v6);
20501  sequence.push_back(v7); sequence.push_back(v8);
20502  sequence.push_back(v9);
20503  }
20504 
20505  template <typename T,
20506  typename Allocator,
20507  template <typename,typename> class Sequence>
20508  inline void push_back(Sequence<T,Allocator>& sequence,
20509  const T& v1, const T& v2, const T& v3, const T& v4,
20510  const T& v5, const T& v6, const T& v7, const T& v8)
20511  {
20512  sequence.push_back(v1); sequence.push_back(v2);
20513  sequence.push_back(v3); sequence.push_back(v4);
20514  sequence.push_back(v5); sequence.push_back(v6);
20515  sequence.push_back(v7); sequence.push_back(v8);
20516  }
20517 
20518  template <typename T,
20519  typename Allocator,
20520  template <typename,typename> class Sequence>
20521  inline void push_back(Sequence<T,Allocator>& sequence,
20522  const T& v1, const T& v2, const T& v3, const T& v4,
20523  const T& v5, const T& v6, const T& v7)
20524  {
20525  sequence.push_back(v1); sequence.push_back(v2);
20526  sequence.push_back(v3); sequence.push_back(v4);
20527  sequence.push_back(v5); sequence.push_back(v6);
20528  sequence.push_back(v7);
20529  }
20530 
20531  template <typename T,
20532  typename Allocator,
20533  template <typename,typename> class Sequence>
20534  inline void push_back(Sequence<T,Allocator>& sequence,
20535  const T& v1, const T& v2, const T& v3, const T& v4,
20536  const T& v5, const T& v6)
20537  {
20538  sequence.push_back(v1); sequence.push_back(v2);
20539  sequence.push_back(v3); sequence.push_back(v4);
20540  sequence.push_back(v5); sequence.push_back(v6);
20541  }
20542 
20543  template <typename T,
20544  typename Allocator,
20545  template <typename,typename> class Sequence>
20546  inline void push_back(Sequence<T,Allocator>& sequence,
20547  const T& v1, const T& v2, const T& v3, const T& v4,
20548  const T& v5)
20549  {
20550  sequence.push_back(v1); sequence.push_back(v2);
20551  sequence.push_back(v3); sequence.push_back(v4);
20552  sequence.push_back(v5);
20553  }
20554 
20555  template <typename T,
20556  typename Allocator,
20557  template <typename,typename> class Sequence>
20558  inline void push_back(Sequence<T,Allocator>& sequence,
20559  const T& v1, const T& v2, const T& v3, const T& v4)
20560  {
20561  sequence.push_back(v1); sequence.push_back(v2);
20562  sequence.push_back(v3); sequence.push_back(v4);
20563  }
20564 
20565  template <typename T,
20566  typename Allocator,
20567  template <typename,typename> class Sequence>
20568  inline void push_back(Sequence<T,Allocator>& sequence,
20569  const T& v1, const T& v2, const T& v3)
20570  {
20571  sequence.push_back(v1); sequence.push_back(v2);
20572  sequence.push_back(v3);
20573  }
20574 
20575  template <typename T,
20576  typename Allocator,
20577  template <typename,typename> class Sequence>
20578  inline void push_back(Sequence<T,Allocator>& sequence,
20579  const T& v1, const T& v2)
20580  {
20581  sequence.push_back(v1); sequence.push_back(v2);
20582  }
20583 
20584  template <typename T,
20585  typename Allocator,
20586  template <typename,typename> class Sequence>
20587  inline void push_back(Sequence<T,Allocator>& sequence,
20588  const T& v1)
20589  {
20590  sequence.push_back(v1);
20591  }
20592 
20593  template <typename T, typename Comparator, typename Allocator>
20594  inline void push_back(std::set<T,Comparator,Allocator>& set,
20595  const T& v1, const T& v2, const T& v3, const T& v4,
20596  const T& v5, const T& v6, const T& v7, const T& v8,
20597  const T& v9, const T& v10)
20598  {
20599  set.insert(v1); set.insert(v2);
20600  set.insert(v3); set.insert(v4);
20601  set.insert(v5); set.insert(v6);
20602  set.insert(v7); set.insert(v8);
20603  set.insert(v9); set.insert(v10);
20604  }
20605 
20606  template <typename T, typename Comparator, typename Allocator>
20607  inline void push_back(std::set<T,Comparator,Allocator>& set,
20608  const T& v1, const T& v2, const T& v3, const T& v4,
20609  const T& v5, const T& v6, const T& v7, const T& v8,
20610  const T& v9)
20611  {
20612  set.insert(v1); set.insert(v2);
20613  set.insert(v3); set.insert(v4);
20614  set.insert(v5); set.insert(v6);
20615  set.insert(v7); set.insert(v8);
20616  set.insert(v9);
20617  }
20618 
20619  template <typename T, typename Comparator, typename Allocator>
20620  inline void push_back(std::set<T,Comparator,Allocator>& set,
20621  const T& v1, const T& v2, const T& v3, const T& v4,
20622  const T& v5, const T& v6, const T& v7, const T& v8)
20623  {
20624  set.insert(v1); set.insert(v2);
20625  set.insert(v3); set.insert(v4);
20626  set.insert(v5); set.insert(v6);
20627  set.insert(v7); set.insert(v8);
20628  }
20629 
20630  template <typename T, typename Comparator, typename Allocator>
20631  inline void push_back(std::set<T,Comparator,Allocator>& set,
20632  const T& v1, const T& v2, const T& v3, const T& v4,
20633  const T& v5, const T& v6, const T& v7)
20634  {
20635  set.insert(v1); set.insert(v2);
20636  set.insert(v3); set.insert(v4);
20637  set.insert(v5); set.insert(v6);
20638  set.insert(v7);
20639  }
20640 
20641  template <typename T, typename Comparator, typename Allocator>
20642  inline void push_back(std::set<T,Comparator,Allocator>& set,
20643  const T& v1, const T& v2, const T& v3, const T& v4,
20644  const T& v5, const T& v6)
20645  {
20646  set.insert(v1); set.insert(v2);
20647  set.insert(v3); set.insert(v4);
20648  set.insert(v5); set.insert(v6);
20649  }
20650 
20651  template <typename T, typename Comparator, typename Allocator>
20652  inline void push_back(std::set<T,Comparator,Allocator>& set,
20653  const T& v1, const T& v2, const T& v3, const T& v4,
20654  const T& v5)
20655  {
20656  set.insert(v1); set.insert(v2);
20657  set.insert(v3); set.insert(v4);
20658  set.insert(v5);
20659  }
20660 
20661  template <typename T, typename Comparator, typename Allocator>
20662  inline void push_back(std::set<T,Comparator,Allocator>& set,
20663  const T& v1, const T& v2, const T& v3, const T& v4)
20664  {
20665  set.insert(v1); set.insert(v2);
20666  set.insert(v3); set.insert(v4);
20667  }
20668 
20669  template <typename T, typename Comparator, typename Allocator>
20670  inline void push_back(std::set<T,Comparator,Allocator>& set,
20671  const T& v1, const T& v2, const T& v3)
20672  {
20673  set.insert(v1); set.insert(v2);
20674  set.insert(v3);
20675  }
20676 
20677  template <typename T, typename Comparator, typename Allocator>
20678  inline void push_back(std::set<T,Comparator,Allocator>& set,
20679  const T& v1, const T& v2)
20680  {
20681  set.insert(v1); set.insert(v2);
20682  }
20683 
20684  template <typename T, typename Comparator, typename Allocator>
20685  inline void push_back(std::set<T,Comparator,Allocator>& set,
20686  const T& v1)
20687  {
20688  set.insert(v1);
20689  }
20690 
20691  template <typename T, typename Comparator, typename Allocator>
20692  inline void push_back(std::multiset<T,Comparator,Allocator>& set,
20693  const T& v1, const T& v2, const T& v3, const T& v4,
20694  const T& v5, const T& v6, const T& v7, const T& v8,
20695  const T& v9, const T& v10)
20696  {
20697  set.insert(v1); set.insert(v2);
20698  set.insert(v3); set.insert(v4);
20699  set.insert(v5); set.insert(v6);
20700  set.insert(v7); set.insert(v8);
20701  set.insert(v9); set.insert(v10);
20702  }
20703 
20704  template <typename T, typename Comparator, typename Allocator>
20705  inline void push_back(std::multiset<T,Comparator,Allocator>& set,
20706  const T& v1, const T& v2, const T& v3, const T& v4,
20707  const T& v5, const T& v6, const T& v7, const T& v8,
20708  const T& v9)
20709  {
20710  set.insert(v1); set.insert(v2);
20711  set.insert(v3); set.insert(v4);
20712  set.insert(v5); set.insert(v6);
20713  set.insert(v7); set.insert(v8);
20714  set.insert(v9);
20715  }
20716 
20717  template <typename T, typename Comparator, typename Allocator>
20718  inline void push_back(std::multiset<T,Comparator,Allocator>& set,
20719  const T& v1, const T& v2, const T& v3, const T& v4,
20720  const T& v5, const T& v6, const T& v7, const T& v8)
20721  {
20722  set.insert(v1); set.insert(v2);
20723  set.insert(v3); set.insert(v4);
20724  set.insert(v5); set.insert(v6);
20725  set.insert(v7); set.insert(v8);
20726  }
20727 
20728  template <typename T, typename Comparator, typename Allocator>
20729  inline void push_back(std::multiset<T,Comparator,Allocator>& set,
20730  const T& v1, const T& v2, const T& v3, const T& v4,
20731  const T& v5, const T& v6, const T& v7)
20732  {
20733  set.insert(v1); set.insert(v2);
20734  set.insert(v3); set.insert(v4);
20735  set.insert(v5); set.insert(v6);
20736  set.insert(v7);
20737  }
20738 
20739  template <typename T, typename Comparator, typename Allocator>
20740  inline void push_back(std::multiset<T,Comparator,Allocator>& set,
20741  const T& v1, const T& v2, const T& v3, const T& v4,
20742  const T& v5, const T& v6)
20743  {
20744  set.insert(v1); set.insert(v2);
20745  set.insert(v3); set.insert(v4);
20746  set.insert(v5); set.insert(v6);
20747  }
20748 
20749  template <typename T, typename Comparator, typename Allocator>
20750  inline void push_back(std::multiset<T,Comparator,Allocator>& set,
20751  const T& v1, const T& v2, const T& v3, const T& v4,
20752  const T& v5)
20753  {
20754  set.insert(v1); set.insert(v2);
20755  set.insert(v3); set.insert(v4);
20756  set.insert(v5);
20757  }
20758 
20759  template <typename T, typename Comparator, typename Allocator>
20760  inline void push_back(std::multiset<T,Comparator,Allocator>& set,
20761  const T& v1, const T& v2, const T& v3, const T& v4)
20762  {
20763  set.insert(v1); set.insert(v2);
20764  set.insert(v3); set.insert(v4);
20765  }
20766 
20767  template <typename T, typename Comparator, typename Allocator>
20768  inline void push_back(std::multiset<T,Comparator,Allocator>& set,
20769  const T& v1, const T& v2, const T& v3)
20770  {
20771  set.insert(v1); set.insert(v2);
20772  set.insert(v3);
20773  }
20774 
20775  template <typename T, typename Comparator, typename Allocator>
20776  inline void push_back(std::multiset<T,Comparator,Allocator>& set,
20777  const T& v1, const T& v2)
20778  {
20779  set.insert(v1); set.insert(v2);
20780  }
20781 
20782  template <typename T, typename Comparator, typename Allocator>
20783  inline void push_back(std::multiset<T,Comparator,Allocator>& set,
20784  const T& v1)
20785  {
20786  set.insert(v1);
20787  }
20788 
20789  template <typename T,
20790  typename Allocator,
20791  template <typename,typename> class Sequence>
20792  inline void clear(Sequence<T,Allocator>& sequence)
20793  {
20794  sequence.clear();
20795  }
20796 
20797  template <typename T,
20798  typename Comparator,
20799  typename Allocator>
20800  inline void clear(std::set<T,Comparator,Allocator>& set)
20801  {
20802  std::set<T> null_set;
20803  std::swap(set,null_set);
20804  }
20805 
20806  template <typename T,
20807  typename Comparator,
20808  typename Allocator>
20809  inline void clear(std::multiset<T,Comparator,Allocator>& multiset)
20810  {
20811  std::multiset<T> null_set;
20812  std::swap(multiset,null_set);
20813  }
20814 
20815  template <typename T, typename Container>
20816  inline void clear(std::queue<T,Container>& queue)
20817  {
20818  std::queue<T> null_que;
20819  std::swap(queue,null_que);
20820  }
20821 
20822  template <typename T, typename Container>
20823  inline void clear(std::stack<T,Container>& stack)
20824  {
20825  std::stack<T> null_stack;
20826  std::swap(stack,null_stack);
20827  }
20828 
20829  template <typename T,
20830  typename Container,
20831  typename Comparator>
20832  inline void clear(std::priority_queue<T,Container,Comparator>& priority_queue)
20833  {
20834  std::priority_queue<T> null_pqueue;
20835  std::swap(priority_queue,null_pqueue);
20836  }
20837 
20838  } // namespace util
20839 
20840  namespace details
20841  {
20842  template <std::size_t N>
20844  {
20845  enum { size = N };
20846  std::size_t index_list[N];
20847  };
20848 
20849  template <typename Cli, std::size_t N>
20851  {
20852  public:
20853 
20856 
20858  : column_list_(column_list),
20859  current_index_(0),
20860  target_index_(column_list_.index_list[0]),
20861  col_list_index_(0),
20862  error_count_(0)
20863  {}
20864 
20865  inline csb_t& operator*()
20866  {
20867  return (*this);
20868  }
20869 
20870  inline csb_t& operator++()
20871  {
20872  return (*this);
20873  }
20874 
20875  inline csb_t operator++(int)
20876  {
20877  return (*this);
20878  }
20879 
20880  template <typename Iterator>
20881  inline csb_t& operator=(const std::pair<Iterator,Iterator>& r)
20882  {
20883  process(r);
20884  return (*this);
20885  }
20886 
20887  void reset()
20888  {
20889  current_index_ = 0;
20890  col_list_index_ = 0;
20891  target_index_ = column_list_.index_list[0];
20892  error_count_ = 0;
20893  }
20894 
20895  protected:
20896 
20898  {
20899  public:
20900 
20901  typedef std::pair<strtk::util::value,bool> value_t;
20902 
20904  : current_index(0)
20905  {
20906  static const value_t null_value(strtk::util::value(),false);
20907  std::fill_n(value_list,N,null_value);
20908  }
20909 
20910  template <typename T>
20911  inline void register_value(T& t)
20912  {
20913  if (current_index < N)
20914  {
20915  value_list[current_index].first.assign(t);
20916  value_list[current_index].second = false;
20917  ++current_index;
20918  }
20919  }
20920 
20921  std::size_t current_index;
20922  value_t value_list[N];
20923  };
20924 
20925  template <typename Iterator>
20926  inline void process(const std::pair<Iterator,Iterator>& r)
20927  {
20928  if (current_index_ > target_index_)
20929  return;
20930  else if (current_index_ == target_index_)
20931  {
20932  typename colsel_value_list::value_t& v = cvl_.value_list[col_list_index_];
20933  if (true != (v.second = v.first(r.first,r.second)))
20934  {
20935  ++error_count_;
20936  }
20937  ++col_list_index_;
20938  if (col_list_index_ < column_list_t::size)
20939  target_index_ = column_list_.index_list[col_list_index_];
20940  else
20941  target_index_ = std::numeric_limits<std::size_t>::max();
20942  }
20943  ++current_index_;
20944  }
20945 
20946  inline colsel_value_list& cvl()
20947  {
20948  return cvl_;
20949  }
20950 
20952  std::size_t current_index_;
20953  std::size_t target_index_;
20954  std::size_t col_list_index_;
20955  std::size_t error_count_;
20956  colsel_value_list cvl_;
20957 
20958  private:
20959 
20960  csb_t& operator=(const csb_t& csb);
20961  };
20962 
20963  template <typename T0 = void, typename T1 = void, typename T2 = void, typename T3 = void, typename T4 = void,
20964  typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void, typename T9 = void,
20965  typename T10 = void, typename T11 = void>
20967  : public column_selector_base<column_selector_impl<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11>,12>
20968  {
20969  public:
20970 
20973 
20975  T0& t0, T1& t1, T2& t2, T3& t3, T4& t4,
20976  T5& t5, T6& t6, T7& t7, T8& t8, T9& t9,
20977  T10& t10, T11& t11)
20978  : csb_t(column_list)
20979  {
20980  csb_t::cvl().register_value( t0); csb_t::cvl().register_value( t1);
20981  csb_t::cvl().register_value( t2); csb_t::cvl().register_value( t3);
20982  csb_t::cvl().register_value( t4); csb_t::cvl().register_value( t5);
20983  csb_t::cvl().register_value( t6); csb_t::cvl().register_value( t7);
20984  csb_t::cvl().register_value( t8); csb_t::cvl().register_value( t9);
20985  csb_t::cvl().register_value(t10); csb_t::cvl().register_value(t11);
20986  }
20987  };
20988 
20989  template <typename T0, typename T1, typename T2, typename T3, typename T4,
20990  typename T5, typename T6, typename T7, typename T8, typename T9,
20991  typename T10>
20992  class column_selector_impl <T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10>
20993  : public column_selector_base<column_selector_impl<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10>,11>
20994  {
20995  public:
20996 
20999 
21001  T0& t0, T1& t1, T2& t2, T3& t3, T4& t4,
21002  T5& t5, T6& t6, T7& t7, T8& t8, T9& t9,
21003  T10& t10)
21004  : csb_t(column_list)
21005  {
21006  csb_t::cvl().register_value( t0); csb_t::cvl().register_value( t1);
21007  csb_t::cvl().register_value( t2); csb_t::cvl().register_value( t3);
21008  csb_t::cvl().register_value( t4); csb_t::cvl().register_value( t5);
21009  csb_t::cvl().register_value( t6); csb_t::cvl().register_value( t7);
21010  csb_t::cvl().register_value( t8); csb_t::cvl().register_value( t9);
21011  csb_t::cvl().register_value(t10);
21012  }
21013  };
21014 
21015  template <typename T0, typename T1, typename T2, typename T3, typename T4,
21016  typename T5, typename T6, typename T7, typename T8, typename T9>
21017  class column_selector_impl <T0,T1,T2,T3,T4,T5,T6,T7,T8,T9>
21018  : public column_selector_base<column_selector_impl<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9>,10>
21019  {
21020  public:
21021 
21024 
21026  T1& t0, T1& t1, T2& t2, T3& t3, T4& t4,
21027  T5& t5, T6& t6, T7& t7, T8& t8, T9& t9)
21028  : csb_t(column_list)
21029  {
21030  csb_t::cvl().register_value(t0); csb_t::cvl().register_value(t1);
21031  csb_t::cvl().register_value(t2); csb_t::cvl().register_value(t3);
21032  csb_t::cvl().register_value(t4); csb_t::cvl().register_value(t5);
21033  csb_t::cvl().register_value(t6); csb_t::cvl().register_value(t7);
21034  csb_t::cvl().register_value(t8); csb_t::cvl().register_value(t9);
21035  }
21036  };
21037 
21038  template <typename T0, typename T1, typename T2, typename T3, typename T4,
21039  typename T5, typename T6, typename T7, typename T8>
21040  class column_selector_impl <T0,T1,T2,T3,T4,T5,T6,T7,T8>
21041  : public column_selector_base<column_selector_impl<T0,T1,T2,T3,T4,T5,T6,T7,T8>,9>
21042  {
21043  public:
21044 
21047 
21049  T1& t0, T1& t1, T2& t2, T3& t3, T4& t4,
21050  T5& t5, T6& t6, T7& t7, T8& t8)
21051  : csb_t(column_list)
21052  {
21053  csb_t::cvl().register_value(t0); csb_t::cvl().register_value(t1);
21054  csb_t::cvl().register_value(t2); csb_t::cvl().register_value(t3);
21055  csb_t::cvl().register_value(t4); csb_t::cvl().register_value(t5);
21056  csb_t::cvl().register_value(t6); csb_t::cvl().register_value(t7);
21057  csb_t::cvl().register_value(t8);
21058  }
21059  };
21060 
21061  template <typename T0, typename T1, typename T2, typename T3,
21062  typename T4, typename T5, typename T6, typename T7>
21063  class column_selector_impl <T0,T1,T2,T3,T4,T5,T6,T7>
21064  : public column_selector_base<column_selector_impl<T0,T1,T2,T3,T4,T5,T6,T7>,8>
21065  {
21066  public:
21067 
21070 
21072  T1& t0, T1& t1, T2& t2, T3& t3,
21073  T4& t4, T5& t5, T6& t6, T7& t7)
21074  : csb_t(column_list)
21075  {
21076  csb_t::cvl().register_value(t0); csb_t::cvl().register_value(t1);
21077  csb_t::cvl().register_value(t2); csb_t::cvl().register_value(t3);
21078  csb_t::cvl().register_value(t4); csb_t::cvl().register_value(t5);
21079  csb_t::cvl().register_value(t6); csb_t::cvl().register_value(t7);
21080  }
21081  };
21082 
21083  template <typename T0, typename T1, typename T2, typename T3,
21084  typename T4, typename T5, typename T6>
21085  class column_selector_impl <T0,T1,T2,T3,T4,T5,T6>
21086  : public column_selector_base<column_selector_impl<T0,T1,T2,T3,T4,T5,T6>,7>
21087  {
21088  public:
21089 
21092 
21094  T1& t0, T1& t1, T2& t2, T3& t3,
21095  T4& t4, T5& t5, T6& t6)
21096  : csb_t(column_list)
21097  {
21098  csb_t::cvl().register_value(t0); csb_t::cvl().register_value(t1);
21099  csb_t::cvl().register_value(t2); csb_t::cvl().register_value(t3);
21100  csb_t::cvl().register_value(t4); csb_t::cvl().register_value(t5);
21101  csb_t::cvl().register_value(t6);
21102  }
21103  };
21104 
21105  template <typename T0, typename T1, typename T2,
21106  typename T3, typename T4, typename T5>
21107  class column_selector_impl <T0,T1,T2,T3,T4,T5>
21108  : public column_selector_base<column_selector_impl<T0,T1,T2,T3,T4,T5>,6>
21109  {
21110  public:
21111 
21114 
21116  T1& t0, T1& t1, T2& t2,
21117  T3& t3, T4& t4, T5& t5)
21118  : csb_t(column_list)
21119  {
21120  csb_t::cvl().register_value(t0); csb_t::cvl().register_value(t1);
21121  csb_t::cvl().register_value(t2); csb_t::cvl().register_value(t3);
21122  csb_t::cvl().register_value(t4); csb_t::cvl().register_value(t5);
21123  }
21124  };
21125 
21126  template <typename T0, typename T1, typename T2,
21127  typename T3, typename T4>
21128  class column_selector_impl <T0,T1,T2,T3,T4>
21129  : public column_selector_base<column_selector_impl<T0,T1,T2,T3,T4>,5>
21130  {
21131  public:
21132 
21135 
21137  T1& t0, T1& t1, T2& t2,
21138  T3& t3, T4& t4)
21139  : csb_t(column_list)
21140  {
21141  csb_t::cvl().register_value(t0); csb_t::cvl().register_value(t1);
21142  csb_t::cvl().register_value(t2); csb_t::cvl().register_value(t3);
21143  csb_t::cvl().register_value(t4);
21144  }
21145  };
21146 
21147  template <typename T0, typename T1, typename T2, typename T3>
21148  class column_selector_impl <T0,T1,T2,T3>
21149  : public column_selector_base<column_selector_impl<T0,T1,T2,T3>,4>
21150  {
21151  public:
21152 
21155 
21157  T1& t0, T1& t1, T2& t2, T3& t3)
21158  : csb_t(column_list)
21159  {
21160  csb_t::cvl().register_value(t0); csb_t::cvl().register_value(t1);
21161  csb_t::cvl().register_value(t2); csb_t::cvl().register_value(t3);
21162  }
21163  };
21164 
21165  template <typename T0, typename T1, typename T2>
21166  class column_selector_impl <T0,T1,T2>
21167  : public column_selector_base<column_selector_impl<T0,T1,T2>,3>
21168  {
21169  public:
21170 
21173 
21175  T1& t0, T1& t1, T2& t2)
21176  : csb_t(column_list)
21177  {
21178  csb_t::cvl().register_value(t0); csb_t::cvl().register_value(t1);
21179  csb_t::cvl().register_value(t2);
21180  }
21181  };
21182 
21183  template <typename T0, typename T1>
21184  class column_selector_impl <T0,T1>
21185  : public column_selector_base<column_selector_impl<T0,T1>,2>
21186  {
21187  public:
21188 
21191 
21193  T1& t0, T1& t1)
21194  : csb_t(column_list)
21195  {
21196  csb_t::cvl().register_value(t0); csb_t::cvl().register_value(t1);
21197  }
21198  };
21199 
21200  template <typename T0>
21202  : public column_selector_base<column_selector_impl<T0>,1>
21203  {
21204  public:
21205 
21208 
21210  : csb_t(column_list)
21211  {
21212  csb_t::cvl().register_value(t0);
21213  }
21214  };
21215 
21216  }
21217 
21218  inline details::column_list_impl<12>
21219  column_list(const std::size_t& idx0, const std::size_t& idx1,
21220  const std::size_t& idx2, const std::size_t& idx3,
21221  const std::size_t& idx4, const std::size_t& idx5,
21222  const std::size_t& idx6, const std::size_t& idx7,
21223  const std::size_t& idx8, const std::size_t& idx9,
21224  const std::size_t& idx10, const std::size_t& idx11)
21225  {
21227  cli.index_list[ 0] = idx0; cli.index_list[ 1] = idx1;
21228  cli.index_list[ 2] = idx2; cli.index_list[ 3] = idx3;
21229  cli.index_list[ 4] = idx4; cli.index_list[ 5] = idx5;
21230  cli.index_list[ 6] = idx6; cli.index_list[ 7] = idx7;
21231  cli.index_list[ 8] = idx8; cli.index_list[ 9] = idx9;
21232  cli.index_list[10] = idx10; cli.index_list[11] = idx11;
21233  return cli;
21234  }
21235 
21236  inline details::column_list_impl<11>
21237  column_list(const std::size_t& idx0, const std::size_t& idx1,
21238  const std::size_t& idx2, const std::size_t& idx3,
21239  const std::size_t& idx4, const std::size_t& idx5,
21240  const std::size_t& idx6, const std::size_t& idx7,
21241  const std::size_t& idx8, const std::size_t& idx9,
21242  const std::size_t& idx10)
21243  {
21245  cli.index_list[ 0] = idx0; cli.index_list[1] = idx1;
21246  cli.index_list[ 2] = idx2; cli.index_list[3] = idx3;
21247  cli.index_list[ 4] = idx4; cli.index_list[5] = idx5;
21248  cli.index_list[ 6] = idx6; cli.index_list[7] = idx7;
21249  cli.index_list[ 8] = idx8; cli.index_list[9] = idx9;
21250  cli.index_list[10] = idx10;
21251  return cli;
21252  }
21253 
21254  inline details::column_list_impl<10>
21255  column_list(const std::size_t& idx0, const std::size_t& idx1,
21256  const std::size_t& idx2, const std::size_t& idx3,
21257  const std::size_t& idx4, const std::size_t& idx5,
21258  const std::size_t& idx6, const std::size_t& idx7,
21259  const std::size_t& idx8, const std::size_t& idx9)
21260  {
21262  cli.index_list[0] = idx0; cli.index_list[1] = idx1;
21263  cli.index_list[2] = idx2; cli.index_list[3] = idx3;
21264  cli.index_list[4] = idx4; cli.index_list[5] = idx5;
21265  cli.index_list[6] = idx6; cli.index_list[7] = idx7;
21266  cli.index_list[8] = idx8; cli.index_list[9] = idx9;
21267  return cli;
21268  }
21269 
21270  inline details::column_list_impl<9>
21271  column_list(const std::size_t& idx0, const std::size_t& idx1,
21272  const std::size_t& idx2, const std::size_t& idx3,
21273  const std::size_t& idx4, const std::size_t& idx5,
21274  const std::size_t& idx6, const std::size_t& idx7,
21275  const std::size_t& idx8)
21276  {
21278  cli.index_list[0] = idx0; cli.index_list[1] = idx1;
21279  cli.index_list[2] = idx2; cli.index_list[3] = idx3;
21280  cli.index_list[4] = idx4; cli.index_list[5] = idx5;
21281  cli.index_list[6] = idx6; cli.index_list[7] = idx7;
21282  cli.index_list[8] = idx8;
21283  return cli;
21284  }
21285 
21286  inline details::column_list_impl<8>
21287  column_list(const std::size_t& idx0, const std::size_t& idx1,
21288  const std::size_t& idx2, const std::size_t& idx3,
21289  const std::size_t& idx4, const std::size_t& idx5,
21290  const std::size_t& idx6, const std::size_t& idx7)
21291  {
21293  cli.index_list[0] = idx0; cli.index_list[1] = idx1;
21294  cli.index_list[2] = idx2; cli.index_list[3] = idx3;
21295  cli.index_list[4] = idx4; cli.index_list[5] = idx5;
21296  cli.index_list[6] = idx6; cli.index_list[7] = idx7;
21297  return cli;
21298  }
21299 
21300  inline details::column_list_impl<7>
21301  column_list(const std::size_t& idx0, const std::size_t& idx1,
21302  const std::size_t& idx2, const std::size_t& idx3,
21303  const std::size_t& idx4, const std::size_t& idx5,
21304  const std::size_t& idx6)
21305  {
21307  cli.index_list[0] = idx0; cli.index_list[1] = idx1;
21308  cli.index_list[2] = idx2; cli.index_list[3] = idx3;
21309  cli.index_list[4] = idx4; cli.index_list[5] = idx5;
21310  cli.index_list[6] = idx6;
21311  return cli;
21312  }
21313 
21314  inline details::column_list_impl<6>
21315  column_list(const std::size_t& idx0, const std::size_t& idx1,
21316  const std::size_t& idx2, const std::size_t& idx3,
21317  const std::size_t& idx4, const std::size_t& idx5)
21318  {
21320  cli.index_list[0] = idx0; cli.index_list[1] = idx1;
21321  cli.index_list[2] = idx2; cli.index_list[3] = idx3;
21322  cli.index_list[4] = idx4; cli.index_list[5] = idx5;
21323  return cli;
21324  }
21325 
21326  inline details::column_list_impl<5>
21327  column_list(const std::size_t& idx0, const std::size_t& idx1,
21328  const std::size_t& idx2, const std::size_t& idx3,
21329  const std::size_t& idx4)
21330  {
21332  cli.index_list[0] = idx0; cli.index_list[1] = idx1;
21333  cli.index_list[2] = idx2; cli.index_list[3] = idx3;
21334  cli.index_list[4] = idx4;
21335  return cli;
21336  }
21337 
21338  inline details::column_list_impl<4>
21339  column_list(const std::size_t& idx0, const std::size_t& idx1,
21340  const std::size_t& idx2, const std::size_t& idx3)
21341  {
21343  cli.index_list[0] = idx0; cli.index_list[1] = idx1;
21344  cli.index_list[2] = idx2; cli.index_list[3] = idx3;
21345  return cli;
21346  }
21347 
21348  inline details::column_list_impl<3>
21349  column_list(const std::size_t& idx0, const std::size_t& idx1,
21350  const std::size_t& idx2)
21351  {
21353  cli.index_list[0] = idx0; cli.index_list[1] = idx1;
21354  cli.index_list[2] = idx2;
21355  return cli;
21356  }
21357 
21358  inline details::column_list_impl<2>
21359  column_list(const std::size_t& idx0, const std::size_t& idx1)
21360  {
21362  cli.index_list[0] = idx0; cli.index_list[1] = idx1;
21363  return cli;
21364  }
21365 
21366  inline details::column_list_impl<1>
21367  column_list(const std::size_t& idx0)
21368  {
21370  cli.index_list[0] = idx0;
21371  return cli;
21372  }
21373 
21374  inline details::column_list_impl<12> column_list(const std::size_t (&idx)[12])
21375  {
21376  return column_list(idx[0],idx[1],idx[2],idx[3],idx[4],idx[5],
21377  idx[6],idx[7],idx[8],idx[9],idx[10],idx[11]);
21378  }
21379 
21380  inline details::column_list_impl<11> column_list(const std::size_t (&idx)[11])
21381  {
21382  return column_list(idx[0],idx[1],idx[2],idx[3],idx[4],idx[5],
21383  idx[6],idx[7],idx[8],idx[9],idx[10]);
21384  }
21385 
21386  inline details::column_list_impl<10> column_list(const std::size_t (&idx)[10])
21387  {
21388  return column_list(idx[0],idx[1],idx[2],idx[3],idx[4],idx[5],
21389  idx[6],idx[7],idx[8],idx[9]);
21390  }
21391 
21392  inline details::column_list_impl<9> column_list(const std::size_t (&idx)[9])
21393  {
21394  return column_list(idx[0],idx[1],idx[2],idx[3],idx[4],idx[5],
21395  idx[6],idx[7],idx[8]);
21396  }
21397 
21398  inline details::column_list_impl<8> column_list(const std::size_t (&idx)[8])
21399  {
21400  return column_list(idx[0],idx[1],idx[2],idx[3],idx[4],idx[5],
21401  idx[6],idx[7]);
21402  }
21403 
21404  inline details::column_list_impl<7> column_list(const std::size_t (&idx)[7])
21405  {
21406  return column_list(idx[0],idx[1],idx[2],idx[3],idx[4],idx[5],idx[6]);
21407  }
21408 
21409  inline details::column_list_impl<6> column_list(const std::size_t (&idx)[6])
21410  {
21411  return column_list(idx[0],idx[1],idx[2],idx[3],idx[4],idx[5]);
21412  }
21413 
21414  inline details::column_list_impl<5> column_list(const std::size_t (&idx)[5])
21415  {
21416  return column_list(idx[0],idx[1],idx[2],idx[3],idx[4]);
21417  }
21418 
21419  inline details::column_list_impl<4> column_list(const std::size_t (&idx)[4])
21420  {
21421  return column_list(idx[0],idx[1],idx[2],idx[3]);
21422  }
21423 
21424  inline details::column_list_impl<3> column_list(const std::size_t (&idx)[3])
21425  {
21426  return column_list(idx[0],idx[1],idx[2]);
21427  }
21428 
21429  inline details::column_list_impl<2> column_list(const std::size_t (&idx)[2])
21430  {
21431  return column_list(idx[0],idx[1]);
21432  }
21433 
21434  inline details::column_list_impl<1> column_list(const std::size_t (&idx)[1])
21435  {
21436  return column_list(idx[0]);
21437  }
21438 
21439  template <typename T0, typename T1, typename T2, typename T3,
21440  typename T4, typename T5, typename T6, typename T7,
21441  typename T8, typename T9, typename T10, typename T11>
21442  inline typename details::column_selector_impl<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9>
21444  T0& t0, T1& t1, T2& t2, T3& t3, T4& t4, T5& t5,
21445  T6& t6, T7& t7, T8& t8, T9& t9, T10& t10, T11& t11)
21446  {
21447  return
21449  <T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11>
21450  (col_list,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11);
21451  }
21452 
21453  template <typename T0, typename T1, typename T2, typename T3,
21454  typename T4, typename T5, typename T6, typename T7,
21455  typename T8, typename T9, typename T10>
21456  inline typename details::column_selector_impl<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9>
21458  T0& t0, T1& t1, T2& t2, T3& t3, T4& t4, T5& t5,
21459  T6& t6, T7& t7, T8& t8, T9& t9, T10& t10)
21460  {
21461  return
21463  <T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10>
21464  (col_list,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10);
21465  }
21466 
21467  template <typename T0, typename T1, typename T2, typename T3,
21468  typename T4, typename T5, typename T6, typename T7,
21469  typename T8, typename T9>
21470  inline typename details::column_selector_impl<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9>
21472  T0& t0, T1& t1, T2& t2, T3& t3, T4& t4, T5& t5,
21473  T6& t6, T7& t7, T8& t8, T9& t9)
21474  {
21475  return
21477  <T0,T1,T2,T3,T4,T5,T6,T7,T8,T9>
21478  (col_list,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9);
21479  }
21480 
21481  template <typename T0, typename T1, typename T2, typename T3,
21482  typename T4, typename T5, typename T6, typename T7,
21483  typename T8>
21484  inline typename details::column_selector_impl<T0,T1,T2,T3,T4,T5,T6,T7,T8>
21486  T0& t0, T1& t1, T2& t2, T3& t3, T4& t4, T5& t5,
21487  T6& t6, T7& t7, T8& t8)
21488  {
21489  return
21491  <T0,T1,T2,T3,T4,T5,T6,T7,T8>
21492  (col_list,t0,t1,t2,t3,t4,t5,t6,t7,t8);
21493  }
21494 
21495  template <typename T0, typename T1, typename T2, typename T3,
21496  typename T4, typename T5, typename T6, typename T7>
21497  inline typename details::column_selector_impl<T0,T1,T2,T3,T4,T5,T6,T7>
21499  T0& t0, T1& t1, T2& t2, T3& t3, T4& t4, T5& t5,
21500  T6& t6, T7& t7)
21501  {
21502  return
21504  <T0,T1,T2,T3,T4,T5,T6,T7>
21505  (col_list,t0,t1,t2,t3,t4,t5,t6,t7);
21506  }
21507 
21508  template <typename T0, typename T1, typename T2, typename T3,
21509  typename T4, typename T5, typename T6>
21510  inline typename details::column_selector_impl<T0,T1,T2,T3,T4,T5,T6>
21512  T0& t0, T1& t1, T2& t2, T3& t3, T4& t4, T5& t5, T6& t6)
21513  {
21514  return
21516  <T0,T1,T2,T3,T4,T5,T6>
21517  (col_list,t0,t1,t2,t3,t4,t5,t6);
21518  }
21519 
21520  template <typename T0, typename T1, typename T2, typename T3,
21521  typename T4, typename T5>
21522  inline typename details::column_selector_impl<T0,T1,T2,T3,T4,T5>
21524  T0& t0, T1& t1, T2& t2, T3& t3, T4& t4, T5& t5)
21525  {
21526  return
21528  <T0,T1,T2,T3,T4,T5>
21529  (col_list,t0,t1,t2,t3,t4,t5);
21530  }
21531 
21532  template <typename T0, typename T1, typename T2,
21533  typename T3, typename T4>
21534  inline typename details::column_selector_impl<T0,T1,T2,T3,T4>
21536  T0& t0, T1& t1, T2& t2, T3& t3, T4& t4)
21537  {
21538  return
21540  <T0,T1,T2,T3,T4>
21541  (col_list,t0,t1,t2,t3,t4);
21542  }
21543 
21544  template <typename T0, typename T1, typename T2, typename T3>
21545  inline typename details::column_selector_impl<T0,T1,T2,T3>
21547  T0& t0, T1& t1, T2& t2, T3& t3)
21548  {
21549  return
21551  <T0,T1,T2,T3>
21552  (col_list,t0,t1,t2,t3);
21553  }
21554 
21555  template <typename T0, typename T1, typename T2>
21556  inline typename details::column_selector_impl<T0,T1,T2>
21558  T0& t0, T1& t1, T2& t2)
21559  {
21560  return
21562  <T0,T1,T2>
21563  (col_list,t0,t1,t2);
21564  }
21565 
21566  template <typename T0, typename T1>
21567  inline typename details::column_selector_impl<T0,T1>
21569  T0& t0, T1& t1)
21570  {
21571  return
21573  <T0,T1>
21574  (col_list,t0,t1);
21575  }
21576 
21577  template <typename T0>
21578  inline typename details::column_selector_impl<T0>
21580  {
21581  return
21583  <T0>
21584  (col_list,t0);
21585  }
21586 
21587  namespace details
21588  {
21589  template <typename Iterator>
21590  inline Iterator inc(Iterator itr, const std::size_t& n)
21591  {
21592  std::advance(itr,n);
21593  return itr;
21594  }
21595 
21596  //Single type column selectors
21597  template <typename T, std::size_t N>
21599  {};
21600 
21601  template <typename T>
21603  {
21606 
21607  template <typename Allocator,
21608  template <typename,typename> class Sequence>
21609  static inline type create(const column_list_t& col_list, Sequence<T,Allocator>& seq)
21610  {
21611  return type(col_list,seq[0]);
21612  }
21613 
21614  template <typename Allocator>
21615  static inline type create(const column_list_t& col_list, std::list<T,Allocator>& list)
21616  {
21617  typename std::list<T,Allocator>::iterator b = list.begin();
21618  return type(col_list,*(b));
21619  }
21620  };
21621 
21622  template <typename T>
21624  {
21627 
21628  template <typename Allocator,
21629  template <typename,typename> class Sequence>
21630  static inline type create(const column_list_t& col_list, Sequence<T,Allocator>& seq)
21631  {
21632  return type(col_list,seq[0],seq[1]);
21633  }
21634 
21635  template <typename Allocator>
21636  static inline type create(const column_list_t& col_list, std::list<T,Allocator>& list)
21637  {
21638  typename std::list<T,Allocator>::iterator b = list.begin();
21639  return type(col_list,*(b),*inc(b,1));
21640  }
21641  };
21642 
21643  template <typename T>
21645  {
21648 
21649  template <typename Allocator,
21650  template <typename,typename> class Sequence>
21651  static inline type create(const column_list_t& col_list, Sequence<T,Allocator>& seq)
21652  {
21653  return type(col_list,seq[0],seq[1],seq[2]);
21654  }
21655 
21656  template <typename Allocator>
21657  static inline type create(const column_list_t& col_list, std::list<T,Allocator>& list)
21658  {
21659  typename std::list<T,Allocator>::iterator b = list.begin();
21660  return type(col_list,*(b),*inc(b,1),*inc(b,2));
21661  }
21662  };
21663 
21664  template <typename T>
21666  {
21669 
21670  template <typename Allocator,
21671  template <typename,typename> class Sequence>
21672  static inline type create(const column_list_t& col_list, Sequence<T,Allocator>& seq)
21673  {
21674  return type(col_list,seq[0],seq[1],seq[2],seq[3]);
21675  }
21676 
21677  template <typename Allocator>
21678  static inline type create(const column_list_t& col_list, std::list<T,Allocator>& list)
21679  {
21680  typename std::list<T,Allocator>::iterator b = list.begin();
21681  return type(col_list,*(b),*inc(b,1),*inc(b,2),*inc(b,3));
21682  }
21683  };
21684 
21685  template <typename T>
21687  {
21690 
21691  template <typename Allocator,
21692  template <typename,typename> class Sequence>
21693  static inline type create(const column_list_t& col_list, Sequence<T,Allocator>& seq)
21694  {
21695  return type(col_list,seq[0],seq[1],seq[2],seq[3],seq[4]);
21696  }
21697 
21698  template <typename Allocator>
21699  static inline type create(const column_list_t& col_list, std::list<T,Allocator>& list)
21700  {
21701  typename std::list<T,Allocator>::iterator b = list.begin();
21702  return type(col_list,*(b),*inc(b,1),*inc(b,2),*inc(b,3),*inc(b,4));
21703  }
21704  };
21705 
21706  template <typename T>
21708  {
21711 
21712  template <typename Allocator,
21713  template <typename,typename> class Sequence>
21714  static inline type create(const column_list_t& col_list, Sequence<T,Allocator>& seq)
21715  {
21716  return type(col_list,seq[0],seq[1],seq[2],seq[3],seq[4],seq[5]);
21717  }
21718 
21719  template <typename Allocator>
21720  static inline type create(const column_list_t& col_list, std::list<T,Allocator>& list)
21721  {
21722  typename std::list<T,Allocator>::iterator b = list.begin();
21723  return type(col_list,*(b),*inc(b,1),*inc(b,2),*inc(b,3),*inc(b,4),*inc(b,5));
21724  }
21725  };
21726 
21727  template <typename T>
21729  {
21732 
21733  template <typename Allocator,
21734  template <typename,typename> class Sequence>
21735  static inline type create(const column_list_t& col_list, Sequence<T,Allocator>& seq)
21736  {
21737  return type(col_list,seq[0],seq[1],seq[2],seq[3],seq[4],seq[5],seq[6]);
21738  }
21739 
21740  template <typename Allocator>
21741  static inline type create(const column_list_t& col_list, std::list<T,Allocator>& list)
21742  {
21743  typename std::list<T,Allocator>::iterator b = list.begin();
21744  return type(col_list,*(b),*inc(b,1),*inc(b,2),*inc(b,3),*inc(b,4),*inc(b,5),*inc(b,6));
21745  }
21746  };
21747 
21748  template <typename T>
21750  {
21753 
21754  template <typename Allocator,
21755  template <typename,typename> class Sequence>
21756  static inline type create(const column_list_t& col_list, Sequence<T,Allocator>& seq)
21757  {
21758  return type(col_list,seq[0],seq[1],seq[2],seq[3],seq[4],seq[5],seq[6],seq[7]);
21759  }
21760 
21761  template <typename Allocator>
21762  static inline type create(const column_list_t& col_list, std::list<T,Allocator>& list)
21763  {
21764  typename std::list<T,Allocator>::iterator b = list.begin();
21765  return type(col_list,*(b),*inc(b,1),*inc(b,2),*inc(b,3),*inc(b,4),*inc(b,5),*inc(b,6),*inc(b,7));
21766  }
21767  };
21768 
21769  template <typename T>
21771  {
21774 
21775  template <typename Allocator,
21776  template <typename,typename> class Sequence>
21777  static inline type create(const column_list_t& col_list, Sequence<T,Allocator>& seq)
21778  {
21779  return type(col_list,seq[0],seq[1],seq[2],seq[3],seq[4],seq[5],seq[6],seq[7],seq[8]);
21780  }
21781 
21782  template <typename Allocator>
21783  static inline type create(const column_list_t& col_list, std::list<T,Allocator>& list)
21784  {
21785  typename std::list<T,Allocator>::iterator b = list.begin();
21786  return type(col_list,*(b),*inc(b,1),*inc(b,2),*inc(b,3),*inc(b,4),*inc(b,5),*inc(b,6),*inc(b,7),*inc(b,8));
21787  }
21788  };
21789 
21790  template <typename T>
21792  {
21795 
21796  template <typename Allocator,
21797  template <typename,typename> class Sequence>
21798  static inline type create(const column_list_t& col_list, Sequence<T,Allocator>& seq)
21799  {
21800  return type(col_list,seq[0],seq[1],seq[2],seq[3],seq[4],seq[5],seq[6],seq[7],seq[8],seq[9]);
21801  }
21802 
21803  template <typename Allocator>
21804  static inline type create(const column_list_t& col_list, std::list<T,Allocator>& list)
21805  {
21806  typename std::list<T,Allocator>::iterator b = list.begin();
21807  return type(col_list,*(b),*inc(b,1),*inc(b,2),*inc(b,3),*inc(b,4),*inc(b,5),*inc(b,6),*inc(b,7),*inc(b,8),*inc(b,9));
21808  }
21809  };
21810 
21811  }
21812 
21813  template <std::size_t N,
21814  typename T,
21815  typename Allocator,
21816  template <typename,typename> class Sequence>
21818  column_selector(const details::column_list_impl<N>& col_list, Sequence<T,Allocator>& seq)
21819  {
21820  if (seq.size() >= N)
21821  {
21822  typedef typename details::compose_st_selector_impl<T,N> composer_t;
21823  return composer_t::create(col_list,seq);
21824  }
21825  else
21826  throw std::invalid_argument("column_selector(sequence/list) - size < N!");
21827  }
21828 
21829  namespace details
21830  {
21831 
21832  template <typename InputIterator, std::size_t N>
21834  {
21835  public:
21836 
21839  typedef std::pair<InputIterator,InputIterator> iterator_type;
21841 
21843  : column_list_(column_list),
21844  token_list_(token_list),
21845  current_index_(0),
21846  target_index_(column_list_.index_list[0]),
21847  col_list_index_(0)
21848  {}
21849 
21850  inline csii_t& operator*()
21851  {
21852  return (*this);
21853  }
21854 
21855  inline csii_t& operator++()
21856  {
21857  return (*this);
21858  }
21859 
21860  inline csii_t operator++(int)
21861  {
21862  return (*this);
21863  }
21864 
21865  template <typename Iterator>
21866  inline csii_t& operator=(const std::pair<Iterator,Iterator>& r)
21867  {
21868  if (current_index_ == target_index_)
21869  {
21870  token_list_[col_list_index_] = r;
21871  ++col_list_index_;
21872  if (col_list_index_ < column_list_t::size)
21873  target_index_ = column_list_.index_list[col_list_index_];
21874  else
21875  target_index_ = std::numeric_limits<std::size_t>::max();
21876  }
21877  ++current_index_;
21878  return (*this);
21879  }
21880 
21881  private:
21882 
21883  csii_t& operator=(const csii_t& csb);
21884 
21885  const column_list_t& column_list_;
21886  iterator_type_ptr token_list_;
21887  std::size_t current_index_;
21888  std::size_t target_index_;
21889  std::size_t col_list_index_;
21890  };
21891 
21892  }
21893 
21894  #define strtk_parse_col_token(Index)\
21895  if (!string_to_type_converter(token_list[Index].first,token_list[Index].second,t##Index)) return false;
21896 
21897  #define strtk_parse_col_token_seq(Index)\
21898  if (!string_to_type_converter(token_list[Index].first,token_list[Index].second,seq[Index])) return false;
21899 
21900  #define strtk_parse_columns_impl(NN)\
21901  static const std::size_t N = NN;\
21902  typedef typename details::is_valid_iterator<InputIterator>::type itr_type;\
21903  typedef std::pair<InputIterator,InputIterator> iterator_type;\
21904  typedef details::column_selector_iterator_impl<InputIterator,N> csii_t;\
21905  const std::size_t token_count = (column_list.index_list[N - 1] + 1);\
21906  iterator_type token_list[N];\
21907  csii_t csii(column_list,token_list);\
21908  const std::size_t parsed_token_count = split_n<InputIterator,csii_t&>\
21909  (delimiters,begin,end,token_count,csii,split_options::compress_delimiters);\
21910  if (token_count > parsed_token_count) return false;\
21911 
21912  #define strk_parse_col_seq\
21913  return parse_columns(data.data(),data.data() + data.size(),delimiters,column_list,seq);
21914 
21915  template <typename InputIterator,
21916  typename T0, typename T1, typename T2, typename T3, typename T4,
21917  typename T5, typename T6, typename T7, typename T8, typename T9,
21918  typename T10, typename T11>
21919  inline bool parse_columns(const InputIterator begin,
21920  const InputIterator end,
21921  const std::string& delimiters,
21923  T0& t0, T1& t1, T2& t2, T3& t3, T4& t4, T5& t5,
21924  T6& t6, T7& t7, T8& t8, T9& t9, T10& t10, T11& t11)
21925  {
21933  return true;
21934  }
21935 
21936  template <typename InputIterator,
21937  typename T0, typename T1, typename T2, typename T3, typename T4,
21938  typename T5, typename T6, typename T7, typename T8, typename T9,
21939  typename T10>
21940  inline bool parse_columns(const InputIterator begin,
21941  const InputIterator end,
21942  const std::string& delimiters,
21944  T0& t0, T1& t1, T2& t2, T3& t3, T4& t4, T5& t5,
21945  T6& t6, T7& t7, T8& t8, T9& t9, T10& t10)
21946  {
21954  return true;
21955  }
21956 
21957  template <typename InputIterator,
21958  typename T0, typename T1, typename T2, typename T3, typename T4,
21959  typename T5, typename T6, typename T7, typename T8, typename T9>
21960  inline bool parse_columns(const InputIterator begin,
21961  const InputIterator end,
21962  const std::string& delimiters,
21964  T0& t0, T1& t1, T2& t2, T3& t3, T4& t4, T5& t5,
21965  T6& t6, T7& t7, T8& t8, T9& t9)
21966  {
21973  return true;
21974  }
21975 
21976  template <typename InputIterator,
21977  typename T0, typename T1, typename T2, typename T3, typename T4,
21978  typename T5, typename T6, typename T7, typename T8>
21979  inline bool parse_columns(const InputIterator begin,
21980  const InputIterator end,
21981  const std::string& delimiters,
21983  T0& t0, T1& t1, T2& t2, T3& t3, T4& t4, T5& t5, T6& t6,
21984  T7& t7, T8& t8)
21985  {
21992  return true;
21993  }
21994 
21995  template <typename InputIterator,
21996  typename T0, typename T1, typename T2, typename T3, typename T4,
21997  typename T5, typename T6, typename T7>
21998  inline bool parse_columns(const InputIterator begin,
21999  const InputIterator end,
22000  const std::string& delimiters,
22002  T0& t0, T1& t1, T2& t2, T3& t3, T4& t4, T5& t5, T6& t6, T7& t7)
22003  {
22009  return true;
22010  }
22011 
22012  template <typename InputIterator,
22013  typename T0, typename T1, typename T2, typename T3, typename T4,
22014  typename T5, typename T6>
22015  inline bool parse_columns(const InputIterator begin,
22016  const InputIterator end,
22017  const std::string& delimiters,
22019  T0& t0, T1& t1, T2& t2, T3& t3, T4& t4, T5& t5, T6& t6)
22020  {
22026  return true;
22027  }
22028 
22029  template <typename InputIterator,
22030  typename T0, typename T1, typename T2, typename T3, typename T4,
22031  typename T5>
22032  inline bool parse_columns(const InputIterator begin,
22033  const InputIterator end,
22034  const std::string& delimiters,
22036  T0& t0, T1& t1, T2& t2, T3& t3, T4& t4, T5& t5)
22037  {
22042  return true;
22043  }
22044 
22045  template <typename InputIterator,
22046  typename T0, typename T1, typename T2, typename T3, typename T4>
22047  inline bool parse_columns(const InputIterator begin,
22048  const InputIterator end,
22049  const std::string& delimiters,
22051  T0& t0, T1& t1, T2& t2, T3& t3, T4& t4)
22052  {
22057  return true;
22058  }
22059 
22060  template <typename InputIterator,
22061  typename T0, typename T1, typename T2, typename T3>
22062  inline bool parse_columns(const InputIterator begin,
22063  const InputIterator end,
22064  const std::string& delimiters,
22066  T0& t0, T1& t1, T2& t2, T3& t3)
22067  {
22071  return true;
22072  }
22073 
22074  template <typename InputIterator,
22075  typename T0, typename T1, typename T2>
22076  inline bool parse_columns(const InputIterator begin,
22077  const InputIterator end,
22078  const std::string& delimiters,
22080  T0& t0, T1& t1, T2& t2)
22081  {
22085  return true;
22086  }
22087 
22088  template <typename InputIterator,
22089  typename T0, typename T1>
22090  inline bool parse_columns(const InputIterator begin,
22091  const InputIterator end,
22092  const std::string& delimiters,
22094  T0& t0, T1& t1)
22095  {
22098  return true;
22099  }
22100 
22101  template <typename InputIterator,
22102  typename T0>
22103  inline bool parse_columns(const InputIterator begin,
22104  const InputIterator end,
22105  const std::string& delimiters,
22107  T0& t0)
22108  {
22111  return true;
22112  }
22113 
22114  template <typename InputIterator,
22115  typename T,
22116  typename Allocator,
22117  template <typename,typename> class Sequence>
22118  inline bool parse_columns(const InputIterator begin,
22119  const InputIterator end,
22120  const std::string& delimiters,
22122  Sequence<T,Allocator>& seq)
22123  {
22131  return true;
22132  }
22133 
22134  template <typename InputIterator,
22135  typename T,
22136  typename Allocator,
22137  template <typename,typename> class Sequence>
22138  inline bool parse_columns(const InputIterator begin,
22139  const InputIterator end,
22140  const std::string& delimiters,
22142  Sequence<T,Allocator>& seq)
22143  {
22151  return true;
22152  }
22153 
22154  template <typename InputIterator,
22155  typename T,
22156  typename Allocator,
22157  template <typename,typename> class Sequence>
22158  inline bool parse_columns(const InputIterator begin,
22159  const InputIterator end,
22160  const std::string& delimiters,
22162  Sequence<T,Allocator>& seq)
22163  {
22170  return true;
22171  }
22172 
22173  template <typename InputIterator,
22174  typename T,
22175  typename Allocator,
22176  template <typename,typename> class Sequence>
22177  inline bool parse_columns(const InputIterator begin,
22178  const InputIterator end,
22179  const std::string& delimiters,
22181  Sequence<T,Allocator>& seq)
22182  {
22189  return true;
22190  }
22191 
22192  template <typename InputIterator,
22193  typename T,
22194  typename Allocator,
22195  template <typename,typename> class Sequence>
22196  inline bool parse_columns(const InputIterator begin,
22197  const InputIterator end,
22198  const std::string& delimiters,
22200  Sequence<T,Allocator>& seq)
22201  {
22207  return true;
22208  }
22209 
22210  template <typename InputIterator,
22211  typename T,
22212  typename Allocator,
22213  template <typename,typename> class Sequence>
22214  inline bool parse_columns(const InputIterator begin,
22215  const InputIterator end,
22216  const std::string& delimiters,
22218  Sequence<T,Allocator>& seq)
22219  {
22225  return true;
22226  }
22227 
22228  template <typename InputIterator,
22229  typename T,
22230  typename Allocator,
22231  template <typename,typename> class Sequence>
22232  inline bool parse_columns(const InputIterator begin,
22233  const InputIterator end,
22234  const std::string& delimiters,
22236  Sequence<T,Allocator>& seq)
22237  {
22242  return true;
22243  }
22244 
22245  template <typename InputIterator,
22246  typename T,
22247  typename Allocator,
22248  template <typename,typename> class Sequence>
22249  inline bool parse_columns(const InputIterator begin,
22250  const InputIterator end,
22251  const std::string& delimiters,
22253  Sequence<T,Allocator>& seq)
22254  {
22259  return true;
22260  }
22261 
22262  template <typename InputIterator,
22263  typename T,
22264  typename Allocator,
22265  template <typename,typename> class Sequence>
22266  inline bool parse_columns(const InputIterator begin,
22267  const InputIterator end,
22268  const std::string& delimiters,
22270  Sequence<T,Allocator>& seq)
22271  {
22275  return true;
22276  }
22277 
22278  template <typename InputIterator,
22279  typename T,
22280  typename Allocator,
22281  template <typename,typename> class Sequence>
22282  inline bool parse_columns(const InputIterator begin,
22283  const InputIterator end,
22284  const std::string& delimiters,
22286  Sequence<T,Allocator>& seq)
22287  {
22291  return true;
22292  }
22293 
22294  template <typename InputIterator,
22295  typename T,
22296  typename Allocator,
22297  template <typename,typename> class Sequence>
22298  inline bool parse_columns(const InputIterator begin,
22299  const InputIterator end,
22300  const std::string& delimiters,
22302  Sequence<T,Allocator>& seq)
22303  {
22306  return true;
22307  }
22308 
22309  template <typename InputIterator,
22310  typename T,
22311  typename Allocator,
22312  template <typename,typename> class Sequence>
22313  inline bool parse_columns(const InputIterator begin,
22314  const InputIterator end,
22315  const std::string& delimiters,
22317  Sequence<T,Allocator>& seq)
22318  {
22321  return true;
22322  }
22323 
22324  #undef strtk_parse_col_token
22325  #undef strtk_parse_col_token_seq
22326  #undef strtk_parse_columns_impl
22327 
22328  #define strtk_parse_col_begin()\
22329  return parse_columns(data.data(),\
22330  data.data() + data.size(),delimiters,\
22331  column_list,
22332 
22333  #define strtk_parse_col_end() );
22334 
22335  template <typename T0, typename T1, typename T2, typename T3, typename T4,
22336  typename T5, typename T6, typename T7, typename T8, typename T9,
22337  typename T10, typename T11>
22338  inline bool parse_columns(const std::string& data,
22339  const std::string& delimiters,
22341  T0& t0, T1& t1, T2& t2, T3& t3, T4& t4,
22342  T5& t5, T6& t6, T7& t7, T8& t8, T9& t9,
22343  T10& t10, T11& t11)
22344  {
22346  t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11
22348  }
22349 
22350  template <typename T0, typename T1, typename T2, typename T3, typename T4,
22351  typename T5, typename T6, typename T7, typename T8, typename T9,
22352  typename T10>
22353  inline bool parse_columns(const std::string& data,
22354  const std::string& delimiters,
22356  T0& t0, T1& t1, T2& t2, T3& t3, T4& t4,
22357  T5& t5, T6& t6, T7& t7, T8& t8, T9& t9,
22358  T10& t10)
22359  {
22361  t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10
22363  }
22364 
22365  template <typename T0, typename T1, typename T2, typename T3, typename T4,
22366  typename T5, typename T6, typename T7, typename T8, typename T9>
22367  inline bool parse_columns(const std::string& data,
22368  const std::string& delimiters,
22370  T0& t0, T1& t1, T2& t2, T3& t3, T4& t4,
22371  T5& t5, T6& t6, T7& t7, T8& t8,
22372  T9& t9)
22373  {
22375  t0,t1,t2,t3,t4,t5,t6,t7,t8,t9
22377  }
22378 
22379  template <typename T0, typename T1, typename T2, typename T3, typename T4,
22380  typename T5, typename T6, typename T7, typename T8>
22381  inline bool parse_columns(const std::string& data,
22382  const std::string& delimiters,
22384  T0& t0, T1& t1, T2& t2, T3& t3, T4& t4,
22385  T5& t5, T6& t6, T7& t7, T8& t8)
22386  {
22388  t0,t1,t2,t3,t4,t5,t6,t7,t8
22390  }
22391 
22392  template <typename T0, typename T1, typename T2, typename T3, typename T4,
22393  typename T5, typename T6, typename T7>
22394  inline bool parse_columns(const std::string& data,
22395  const std::string& delimiters,
22397  T0& t0, T1& t1, T2& t2, T3& t3, T4& t4,
22398  T5& t5, T6& t6, T7& t7)
22399  {
22401  t0,t1,t2,t3,t4,t5,t6,t7
22403  }
22404 
22405  template <typename T0, typename T1, typename T2, typename T3, typename T4,
22406  typename T5, typename T6>
22407  inline bool parse_columns(const std::string& data,
22408  const std::string& delimiters,
22410  T0& t0, T1& t1, T2& t2, T3& t3, T4& t4,
22411  T5& t5, T6& t6)
22412  {
22414  t0,t1,t2,t3,t4,t5,t6
22416  }
22417 
22418  template <typename T0, typename T1, typename T2, typename T3, typename T4,
22419  typename T5>
22420  inline bool parse_columns(const std::string& data,
22421  const std::string& delimiters,
22423  T0& t0, T1& t1, T2& t2, T3& t3, T4& t4,
22424  T5& t5)
22425  {
22427  t0,t1,t2,t3,t4,t5
22429  }
22430 
22431  template <typename T0, typename T1, typename T2, typename T3, typename T4>
22432  inline bool parse_columns(const std::string& data,
22433  const std::string& delimiters,
22435  T0& t0, T1& t1, T2& t2, T3& t3, T4& t4)
22436  {
22438  t0,t1,t2,t3,t4
22440  }
22441 
22442  template <typename T0, typename T1, typename T2, typename T3>
22443  inline bool parse_columns(const std::string& data,
22444  const std::string& delimiters,
22446  T0& t0, T1& t1, T2& t2, T3& t3)
22447  {
22449  t0,t1,t2,t3
22451  }
22452 
22453  template <typename T0, typename T1, typename T2>
22454  inline bool parse_columns(const std::string& data,
22455  const std::string& delimiters,
22457  T0& t0, T1& t1, T2& t2)
22458  {
22460  t0,t1,t2
22462  }
22463 
22464  template <typename T0, typename T1>
22465  inline bool parse_columns(const std::string& data,
22466  const std::string& delimiters,
22468  T0& t0, T1& t1)
22469  {
22471  t0,t1
22473  }
22474 
22475  template <typename T>
22476  inline bool parse_columns(const std::string& data,
22477  const std::string& delimiters,
22479  T& t)
22480  {
22482  t
22484  }
22485 
22486  #undef strtk_parse_col_begin
22487  #undef strtk_parse_col_end
22488 
22489  template <typename T,
22490  typename Allocator,
22491  template <typename,typename> class Sequence>
22492  inline bool parse_columns(const std::string& data,
22493  const std::string& delimiters,
22495  Sequence<T,Allocator>& seq)
22496  {
22498  }
22499 
22500  template <typename T,
22501  typename Allocator,
22502  template <typename,typename> class Sequence>
22503  inline bool parse_columns(const std::string& data,
22504  const std::string& delimiters,
22506  Sequence<T,Allocator>& seq)
22507  {
22509  }
22510 
22511  template <typename T,
22512  typename Allocator,
22513  template <typename,typename> class Sequence>
22514  inline bool parse_columns(const std::string& data,
22515  const std::string& delimiters,
22517  Sequence<T,Allocator>& seq)
22518  {
22520  }
22521 
22522  template <typename T,
22523  typename Allocator,
22524  template <typename,typename> class Sequence>
22525  inline bool parse_columns(const std::string& data,
22526  const std::string& delimiters,
22528  Sequence<T,Allocator>& seq)
22529  {
22531  }
22532 
22533  template <typename T,
22534  typename Allocator,
22535  template <typename,typename> class Sequence>
22536  inline bool parse_columns(const std::string& data,
22537  const std::string& delimiters,
22539  Sequence<T,Allocator>& seq)
22540  {
22542  }
22543 
22544  template <typename T,
22545  typename Allocator,
22546  template <typename,typename> class Sequence>
22547  inline bool parse_columns(const std::string& data,
22548  const std::string& delimiters,
22550  Sequence<T,Allocator>& seq)
22551  {
22553  }
22554 
22555  template <typename T,
22556  typename Allocator,
22557  template <typename,typename> class Sequence>
22558  inline bool parse_columns(const std::string& data,
22559  const std::string& delimiters,
22561  Sequence<T,Allocator>& seq)
22562  {
22564  }
22565 
22566  template <typename T,
22567  typename Allocator,
22568  template <typename,typename> class Sequence>
22569  inline bool parse_columns(const std::string& data,
22570  const std::string& delimiters,
22572  Sequence<T,Allocator>& seq)
22573  {
22575  }
22576 
22577  template <typename T,
22578  typename Allocator,
22579  template <typename,typename> class Sequence>
22580  inline bool parse_columns(const std::string& data,
22581  const std::string& delimiters,
22583  Sequence<T,Allocator>& seq)
22584  {
22586  }
22587 
22588  template <typename T,
22589  typename Allocator,
22590  template <typename,typename> class Sequence>
22591  inline bool parse_columns(const std::string& data,
22592  const std::string& delimiters,
22594  Sequence<T,Allocator>& seq)
22595  {
22597  }
22598 
22599  template <typename T,
22600  typename Allocator,
22601  template <typename,typename> class Sequence>
22602  inline bool parse_columns(const std::string& data,
22603  const std::string& delimiters,
22605  Sequence<T,Allocator>& seq)
22606  {
22608  }
22609 
22610  template <typename T,
22611  typename Allocator,
22612  template <typename,typename> class Sequence>
22613  inline bool parse_columns(const std::string& data,
22614  const std::string& delimiters,
22616  Sequence<T,Allocator>& seq)
22617  {
22619  }
22620 
22621  #undef strk_parse_col_seq
22622 
22623  namespace details
22624  {
22625  typedef const unsigned char* ptr;
22626 
22627  template <typename T>
22628  bool cmpimpl(ptr c1, ptr c2) { return (*reinterpret_cast<T>(c1)) == (*reinterpret_cast<T>(c2)); }
22629 
22630  template <std::size_t K>
22631  struct size_impl { static inline bool cmp(ptr,ptr) { return true; } };
22632 
22633  template <>
22634  struct size_impl<8> { static inline bool cmp(ptr c1, ptr c2) { return cmpimpl<const unsigned long long*>(c1,c2); } };
22635 
22636  template <>
22637  struct size_impl<4> { static inline bool cmp(ptr c1, ptr c2) { return cmpimpl<const unsigned int*>(c1,c2); } };
22638 
22639  template <>
22640  struct size_impl<2> { static inline bool cmp(ptr c1, ptr c2) { return cmpimpl<const unsigned short*>(c1,c2); } };
22641 
22642  template <>
22643  struct size_impl<1> { static inline bool cmp(ptr c1, ptr c2) { return cmpimpl<const unsigned char*>(c1,c2); } };
22644 
22645  template <std::size_t N>
22646  struct next_size { enum { size = (N >= 8) ? 8 : ((N >= 4) ? 4 : ((N >= 2) ? 2 : 1)) }; };
22647 
22648  template <std::size_t N>
22650  {
22651  static inline bool process(details::ptr c1, details::ptr c2)
22652  {
22653  static const std::size_t size = details::next_size<N>::size;
22654  return details::size_impl<size>::cmp(c1,c2) && memcmp_n_impl<N - size>::process(c1 + size, c2 + size);
22655  }
22656 
22657  static inline bool process(const char* c1, const char* c2)
22658  {
22659  return memcmp_n_impl<N>::process(reinterpret_cast<details::ptr>(c1),reinterpret_cast<details::ptr>(c2));
22660  }
22661 
22662  template <std::size_t K1, std::size_t K2>
22663  static inline bool process(const unsigned char (&c1)[K1], const unsigned char (&c2)[K2])
22664  {
22665  return memcmp_n_impl<N>::process(static_cast<ptr>(c1),static_cast<ptr>(c2));
22666  }
22667  };
22668 
22669  template<> struct memcmp_n_impl<0> { static inline bool process(ptr,ptr) { return true; } };
22670  }
22671 
22672  template <std::size_t N>
22673  inline bool memcmp_n(details::ptr c1, details::ptr c2)
22674  {
22675  return details::memcmp_n_impl<N>::process(c1,c2);
22676  }
22677 
22678  template <std::size_t N>
22679  inline bool memcmp_n(const char* c1, const char* c2)
22680  {
22681  return details::memcmp_n_impl<N>::process(c1,c2);
22682  }
22683 
22684  template <std::size_t N,std::size_t K1, std::size_t K2>
22685  inline bool memcmp_n(const unsigned char (&c1)[K1], const unsigned char (&c2)[K2])
22686  {
22687  return details::memcmp_n_impl<N>::process(c1,c2);
22688  }
22689 
22690  namespace details
22691  {
22693  {
22694  return v.to_string(result);
22695  }
22696  }
22697 
22698  template <typename Iterator>
22699  inline std::size_t distance(const std::pair<Iterator,Iterator>& p)
22700  {
22701  return std::distance(p.first,p.second);
22702  }
22703 
22704  template <typename Iterator1, typename Iterator2>
22705  inline std::pair<Iterator1,Iterator2> make_pair(const std::string& s)
22706  {
22707  return std::make_pair<Iterator1,Iterator2>(
22708  reinterpret_cast<Iterator1>(const_cast<char*>(s.data())),
22709  reinterpret_cast<Iterator2>(const_cast<char*>(s.data() + s.size())));
22710  }
22711 
22712  template <typename Iterator1, typename Iterator2>
22713  inline std::pair<Iterator1,Iterator2> make_pair(const std::pair<const char*, const char*> p)
22714  {
22715  return std::make_pair<Iterator1,Iterator2>(
22716  reinterpret_cast<Iterator1>(const_cast<char*>(p.first)),
22717  reinterpret_cast<Iterator2>(const_cast<char*>(p.second)));
22718  }
22719 
22720  template <typename Iterator>
22721  inline std::pair<Iterator,Iterator> make_pair(const std::string& s)
22722  {
22723  return make_pair<Iterator,Iterator>(s);
22724  }
22725 
22726  template <typename Iterator>
22727  inline std::pair<Iterator,Iterator> make_pair(const std::pair<const char*, const char*>& p)
22728  {
22729  return make_pair<Iterator,Iterator>(p);
22730  }
22731 
22732  template <typename Iterator1, typename Iterator2>
22733  inline std::pair<Iterator1,Iterator2> make_pair(const strtk::range::string& range)
22734  {
22735  return std::make_pair<Iterator1,Iterator2>(
22736  reinterpret_cast<Iterator1>(const_cast<char*>(range.begin())),
22737  reinterpret_cast<Iterator2>(const_cast<char*>(range.end())));
22738  }
22739 
22740  template <std::size_t N>
22741  inline std::string make_string(const unsigned char (&s)[N], const std::size_t& length = N)
22742  {
22743  static const std::string null_string;
22744  if (N < length)
22745  return null_string;
22746  else
22747  return std::string(&s[0],&s[0] + length);
22748  }
22749 
22750  template <std::size_t N>
22751  inline std::string make_string(const char (&s)[N], const std::size_t& length = N)
22752  {
22753  static const std::string null_string;
22754  if (N < length)
22755  return null_string;
22756  else
22757  return std::string(&s[0],&s[0] + length);
22758  }
22759 
22760  inline std::string make_string(const std::pair<const char*,const char*>& range)
22761  {
22762  return std::string(range.first,range.second);
22763  }
22764 
22765  template <typename T, std::size_t N>
22766  inline bool clear_array(T (&a)[N], const T& t, const std::size_t& length = N)
22767  {
22768  if (N < length)
22769  return false;
22770  else
22771  std::fill_n(&a[0],length,t);
22772  return true;
22773  }
22774 
22775  template <std::size_t N>
22776  inline bool set_array(unsigned char (&a)[N],
22777  const std::string& s,
22778  const bool pad = false,
22779  const unsigned char padding = '0')
22780  {
22781  if (N < s.size())
22782  return false;
22783  std::copy(s.data(),s.data() + s.size(), &a[0]);
22784  if ((s.size() < N) && pad)
22785  std::fill_n(&a[s.size()],N - s.size(),padding);
22786  return true;
22787  }
22788 
22789  template <std::size_t N, std::size_t M>
22790  inline bool set_array(unsigned char (&dest)[N],
22791  unsigned char (&src)[M],
22792  const bool pad = false,
22793  const unsigned char padding = '0')
22794  {
22795  if (N < M)
22796  return false;
22797  std::copy(src,src + N, &dest[0]);
22798  if ((M < N) && pad)
22799  std::fill_n(&dest[M],N - M,padding);
22800  return true;
22801  }
22802 
22803  inline void reverse(const std_string::iterator_type& range)
22804  {
22805  char* begin = const_cast<char*>(range.first);
22806  char* end = const_cast<char*>(range.second);
22807  std::reverse(begin,end);
22808  }
22809 
22810  template <typename T>
22811  inline void reverse(const range::adapter<T>& r)
22812  {
22813  T* begin = const_cast<T*>(r.begin());
22814  T* end = const_cast<T*>(r.end());
22815  std::reverse(begin,end);
22816  }
22817 
22818  template <typename T>
22819  inline void reverse(const range::adapter<const T>& r)
22820  {
22821  T* begin = const_cast<T*>(r.begin());
22822  T* end = const_cast<T*>(r.end());
22823  std::reverse(begin,end);
22824  }
22825 
22826  inline void reverse(std::string& s)
22827  {
22828  std::reverse(s.begin(),s.end());
22829  }
22830 
22831  inline void fill(std::string& s, const std::string::value_type v)
22832  {
22833  std::fill(const_cast<char*>(s.data()),const_cast<char*>(s.data() + s.size()), v);
22834  }
22835 
22836  inline void fill(const std::pair<const char*,const char*>& range, char v)
22837  {
22838  char* begin = const_cast<char*>(range.first);
22839  char* end = const_cast<char*>(range.second);
22840  std::fill(begin,end,v);
22841  }
22842 
22843  template <typename T>
22844  inline void fill(const range::adapter<const T>& r, const typename range::adapter<const T>::value_type& v)
22845  {
22846  char* begin = const_cast<char*>(r.begin());
22847  char* end = const_cast<char*>(r.end());
22848  std::fill(begin,end,v);
22849  }
22850 
22851  inline void fill(const std_string::iterator_type& range, const std::string::value_type& v)
22852  {
22853  char* begin = const_cast<char*>(range.first);
22854  char* end = const_cast<char*>(range.second);
22855  std::fill(begin,end,v);
22856  }
22857 
22858  template <typename T,
22859  typename Allocator,
22860  template <typename,typename> class Sequence>
22861  inline void fill(Sequence<T,Allocator>& seq, const T& t)
22862  {
22863  if (seq.empty())
22864  return;
22865  fill_n(seq.begin(),seq.size(),t);
22866  }
22867 
22868  namespace keyvalue
22869  {
22870  template <typename CharType>
22871  struct options
22872  {
22873  typedef CharType char_type;
22874 
22876  : pair_block_delimiter(0),
22877  pair_delimiter(0)
22878  {}
22879 
22882  };
22883 
22884  template <typename KeyValueMap>
22885  class parser
22886  {
22887  public:
22888 
22889  typedef unsigned char char_type;
22890  typedef std::pair<char_type*,char_type*> range_type;
22891 
22892  template <typename Options>
22893  parser(const Options& opts)
22894  : options_(opts),
22895  kv_map_(opts),
22896  pair_block_sdp_(options_.pair_block_delimiter),
22897  pair_delimiter_sdp_(options_.pair_delimiter)
22898  {
22899  pair_list_.reserve(strtk::one_kilobyte);
22900  }
22901 
22902  template <typename T>
22903  inline bool register_keyvalue(const typename KeyValueMap::key_type& key, T& t)
22904  {
22905  return kv_map_.register_keyvalue(key,t);
22906  }
22907 
22908  inline bool operator()(const range_type& data, const bool ignore_failures = false)
22909  {
22910  if (!ignore_failures)
22911  {
22912  const std::size_t pair_count = split(pair_block_sdp_,
22913  data.first,
22914  data.second,
22915  pair_list_.begin());
22916  if (0 == pair_count)
22917  return false;
22918 
22919  range_type key_range;
22920  range_type value_range;
22921 
22922  for (std::size_t i = 0; i < pair_count; ++i)
22923  {
22924  const range_type& r = pair_list_[i];
22925  if (0 == std::distance(r.first,r.second))
22926  continue;
22927  else if (!split_pair(r.first,r.second,
22928  pair_delimiter_sdp_,
22929  key_range,value_range))
22930  return false;
22931  else if (!kv_map_(key_range,value_range))
22932  return false;
22933  }
22934  return true;
22935  }
22936  else
22937  {
22938  parse_failures_ = 0;
22939  pair_token_processor processor(*this);
22940  split(pair_block_sdp_,
22941  data.first,
22942  data.second,
22943  strtk::functional_inserter(processor));
22944  return true;
22945  }
22946  }
22947 
22948  inline bool operator()(const std::string& s, const bool ignore_failures = false)
22949  {
22950  return operator()(strtk::make_pair<range_type::first_type>(s),ignore_failures);
22951  }
22952 
22953  inline std::size_t failure_count() const
22954  {
22955  return parse_failures_;
22956  }
22957 
22958  private:
22959 
22960  class pair_token_processor
22961  {
22962  public:
22963 
22964  pair_token_processor(parser<KeyValueMap>& p)
22965  : parser_(p)
22966  {}
22967 
22968  inline void operator()(const range_type& r)
22969  {
22970  if (r.first == r.second)
22971  return;
22972  if (split_pair(r.first,r.second,
22973  parser_.pair_delimiter_sdp_,
22974  key_range,
22975  value_range))
22976  {
22977  if (!parser_.kv_map_(key_range,value_range))
22978  ++parser_.parse_failures_;
22979  }
22980  else
22981  ++parser_.parse_failures_;
22982  }
22983 
22984  private:
22985 
22986  pair_token_processor operator=(const pair_token_processor&);
22987 
22988  parser<KeyValueMap>& parser_;
22989  range_type key_range;
22990  range_type value_range;
22991  };
22992 
22993  options<char_type> options_;
22994  std::size_t parse_failures_;
22995  KeyValueMap kv_map_;
22996  single_delimiter_predicate<char_type> pair_block_sdp_;
22997  single_delimiter_predicate<char_type> pair_delimiter_sdp_;
22998  std::vector<range_type> pair_list_;
22999  };
23000 
23002  {
23003  private:
23004 
23005  typedef unsigned char char_type;
23007 
23008  public:
23009 
23010  typedef unsigned int key_type;
23011 
23012  struct options : public general_options
23013  {
23015  : general_options(),
23016  key_count(0)
23017  {}
23018 
23019  std::size_t key_count;
23020  };
23021 
23022  template <typename Options>
23023  uintkey_map(const Options& options)
23024  {
23025  value_lut_.resize(options.key_count,strtk::util::value());
23026  }
23027 
23028  virtual ~uintkey_map()
23029  {}
23030 
23031  template <typename Range>
23032  inline bool operator()(const Range& key_range, const Range& value_range)
23033  {
23034  std::size_t key = 0;
23035  if (!fast::numeric_convert(distance(key_range),key_range.first,key,true))
23036  return false;
23037  if (key >= value_lut_.size())
23038  return false;
23039  const strtk::util::value& v = value_lut_[key];
23040  if (!v)
23041  return false;
23042  else
23043  return v(value_range);
23044  }
23045 
23046  template <typename T>
23047  inline bool register_keyvalue(const key_type& key, T& t)
23048  {
23049  if (key < value_lut_.size())
23050  {
23051  strtk::util::value& v = value_lut_[key];
23052  if (!v)
23053  v = strtk::util::value(t);
23054  else
23055  v.assign(t);
23056  return true;
23057  }
23058  else
23059  return false;
23060  }
23061 
23062  private:
23063 
23064  std::vector<strtk::util::value> value_lut_;
23065  };
23066 
23067  namespace details
23068  {
23069  template <typename Range,typename KType>
23070  struct keygen
23071  {
23072  static inline KType transform(const Range&)
23073  {
23074  return KType();
23075  }
23076  };
23077 
23078  template <typename Range>
23079  struct keygen<Range,std::string>
23080  {
23081  static inline std::string transform(const Range& key_range)
23082  {
23083  return std::string(key_range.first,key_range.second);
23084  }
23085  };
23086 
23087  template <typename Range>
23088  struct keygen<Range,unsigned int>
23089  {
23090  static inline unsigned int transform(const Range& key_range)
23091  {
23092  unsigned int result = 0;
23093  if (strtk::fast::numeric_convert(std::distance(key_range.first,key_range.second),key_range.first,result,true))
23094  return result;
23095  else
23096  return std::numeric_limits<unsigned int>::max();
23097  }
23098  };
23099 
23101  {
23102  template <typename Range>
23103  inline bool operator()(const Range&)
23104  {
23105  return true;
23106  }
23107  };
23108  }
23109 
23110  template <typename KeyType,
23111  typename MapType = std::map<KeyType,strtk::util::value>,
23112  typename KeyValidator = details::no_op_validator,
23113  typename ValueValidator = details::no_op_validator>
23114  class key_map
23115  {
23116  public:
23117 
23118  typedef KeyType key_type;
23119  typedef MapType map_type;
23120  typedef KeyValidator key_validator_type;
23121  typedef ValueValidator value_validator_type;
23122 
23123  template <typename Options>
23124  key_map(const Options&)
23125  {}
23126 
23127  virtual ~key_map()
23128  {}
23129 
23130  template <typename Range>
23131  inline bool operator()(const Range& key_range, const Range& value_range)
23132  {
23133  if (!key_validator_(key_range))
23134  return false;
23135  if (!val_validator_(value_range))
23136  return false;
23137  typename map_type::iterator itr = value_map_.find(details::keygen<Range,key_type>::transform(key_range));
23138  if (value_map_.end() == itr)
23139  return false;
23140  const util::value& v = (*itr).second;
23141  if (!v)
23142  return false;
23143  else
23144  return v(value_range);
23145  }
23146 
23147  template <typename T>
23148  inline bool register_keyvalue(const key_type& key, T& t)
23149  {
23150  strtk::util::value& v = value_map_[key];
23151  if (!v)
23152  v = strtk::util::value(t);
23153  else
23154  v.assign(t);
23155  return true;
23156  }
23157 
23158  private:
23159 
23160  map_type value_map_;
23161  key_validator_type key_validator_;
23162  value_validator_type val_validator_;
23163  };
23164 
23166 
23167  }
23168 } // namespace strtk
23169 
23170 namespace
23171 {
23172 
23173  static inline std::ostream& operator<<(std::ostream& os,
23175  {
23176  os << std::string((*range).first,(*range).second);
23177  return os;
23178  }
23179 
23180  static inline std::ostream& operator<<(std::ostream& os,
23182  {
23183  os << std::string((*range).first,(*range).second);
23184  return os;
23185  }
23186 
23187  static inline std::ostream& operator<<(std::ostream& os,
23189  {
23190  os << std::string((*range).first,(*range).second);
23191  return os;
23192  }
23193 
23194  #define strtk_register_pair_to_ostream(Iterator)\
23195  static inline std::ostream& operator<<(std::ostream& os, const std::pair<Iterator,Iterator>& range)\
23196  { os << std::string(range.first,range.second); return os; }\
23197  static inline std::ostream& operator<<(std::ostream& os, std::pair<Iterator,Iterator>& range)\
23198  { os << std::string(range.first,range.second); return os; }\
23199 
23201  strtk_register_pair_to_ostream(unsigned char*)
23202  strtk_register_pair_to_ostream(const char*)
23203  strtk_register_pair_to_ostream(const unsigned char*)
23204  strtk_register_pair_to_ostream(std::string::iterator)
23205  strtk_register_pair_to_ostream(std::string::const_iterator)
23206  strtk_register_pair_to_ostream(const std::string::iterator)
23207  strtk_register_pair_to_ostream(const std::string::const_iterator)
23208 
23209  #undef strtk_register_pair_to_ostream
23210 
23211 } // namespace anonymous
23212 
23213 #ifdef WIN32
23214  #ifndef NOMINMAX
23215  #define NOMINMAX
23216  #endif
23217  #ifndef WIN32_LEAN_AND_MEAN
23218  #define WIN32_LEAN_AND_MEAN
23219  #endif
23220  #include <windows.h>
23221 #else
23222  #include <sys/time.h>
23223  #include <sys/types.h>
23224 #endif
23225 namespace strtk
23226 {
23227  namespace util
23228  {
23229  class timer
23230  {
23231  public:
23232 
23233  #ifdef WIN32
23234  timer()
23235  : in_use_(false)
23236  {
23237  QueryPerformanceFrequency(&clock_frequency_);
23238  }
23239 
23240  inline void start()
23241  {
23242  in_use_ = true;
23243  QueryPerformanceCounter(&start_time_);
23244  }
23245 
23246  inline void stop()
23247  {
23248  QueryPerformanceCounter(&stop_time_);
23249  in_use_ = false;
23250  }
23251 
23252  inline double time() const
23253  {
23254  return (1.0 * (stop_time_.QuadPart - start_time_.QuadPart)) / (1.0 * clock_frequency_.QuadPart);
23255  }
23256 
23257  #else
23258 
23260  : in_use_(false)
23261  {
23262  start_time_.tv_sec = 0;
23263  start_time_.tv_usec = 0;
23264  stop_time_.tv_sec = 0;
23265  stop_time_.tv_usec = 0;
23266  }
23267 
23268  inline void start()
23269  {
23270  in_use_ = true;
23271  gettimeofday(&start_time_,0);
23272  }
23273 
23274  inline void stop()
23275  {
23276  gettimeofday(&stop_time_, 0);
23277  in_use_ = false;
23278  }
23279 
23280  inline unsigned long long int usec_time() const
23281  {
23282  if (!in_use_)
23283  {
23284  if (stop_time_.tv_sec >= start_time_.tv_sec)
23285  {
23286  return 1000000 * (stop_time_.tv_sec - start_time_.tv_sec ) +
23287  (stop_time_.tv_usec - start_time_.tv_usec);
23288  }
23289  else
23290  return std::numeric_limits<unsigned long long int>::max();
23291  }
23292  else
23293  return std::numeric_limits<unsigned long long int>::max();
23294  }
23295 
23296  inline double time() const
23297  {
23298  return usec_time() * 0.000001;
23299  }
23300 
23301  #endif
23302 
23303  inline bool in_use() const
23304  {
23305  return in_use_;
23306  }
23307 
23308  private:
23309 
23310  bool in_use_;
23311 
23312  #ifdef WIN32
23313  LARGE_INTEGER start_time_;
23314  LARGE_INTEGER stop_time_;
23315  LARGE_INTEGER clock_frequency_;
23316  #else
23317  struct timeval start_time_;
23318  struct timeval stop_time_;
23319  #endif
23320  };
23321 
23323  {
23324  public:
23325 
23326  scoped_timer(double& time_value)
23327  : time_value_(time_value)
23328  {
23329  t_.start();
23330  }
23331 
23333  {
23334  t_.stop();
23335  time_value_ = t_.time();
23336  }
23337 
23338  private:
23339 
23340  scoped_timer(const scoped_timer&);
23341  scoped_timer& operator=(const scoped_timer&);
23342 
23343  double& time_value_;
23344  timer t_;
23345  };
23346 
23347  } // namespace util
23348 
23349  namespace information
23350  {
23351  static const char* library = "String Toolkit";
23352  static const char* version = "2.71828182845904523536028747135266249775724709369";
23353  static const char* date = "20130126";
23354 
23355  static inline std::string data()
23356  {
23357  static const std::string info_str = std::string(library) +
23358  std::string(" v") + std::string(version) +
23359  std::string(" (") + date + std::string(")");
23360  return info_str;
23361  }
23362 
23363  } // namespace information
23364 
23365 } // namespace strtk
23366 
23367 #endif
std::size_t for_each_line_n(std::istream &stream, const std::size_t &n, Function function, const std::size_t &buffer_size=one_kilobyte)
Definition: strtk.hpp:110
bool parse_with_index(const std::size_t &col0, const std::size_t &col1, const std::size_t &col2, T0 &t0, T1 &t1, T2 &t2) const
Definition: strtk.hpp:5481
column_selector_base< column_selector_impl< T0, T1, T2, T3, T4, T5 >, 6 > csb_t
Definition: strtk.hpp:21112
inserter_with_valuetype_iterator & operator++()
Definition: strtk.hpp:2806
char operator()(const char c) const
Definition: strtk.hpp:10915
bool range_only_contains(Predicate predicate, const InputIterator begin, const InputIterator end)
Definition: strtk.hpp:810
bool extract_column_checked(const std::size_t &index, OutputIterator out) const
Definition: strtk.hpp:6176
void operator()(const std::pair< Iterator, Iterator > &r) const
Definition: strtk.hpp:2520
bool sequential_partition(const row_range_t &row_range, TransitionPredicate p, Function f)
Definition: strtk.hpp:6773
std::size_t file_size(const std::string &file_name)
Definition: strtk.hpp:17376
strtk::tokenizer< string_iterator_type, DelimiterPredicate > type
Definition: strtk.hpp:2460
bool contains(const T &t) const
Definition: strtk.hpp:19110
bool extract_column(const row_range_t &row_range, const std::size_t &index, OutputIterator out) const
Definition: strtk.hpp:6210
bool load(const std::string &file_name, const token_grid::options &options)
Definition: strtk.hpp:6835
void skip_while_matching(Iterator &itr, const Iterator &end, const MatchPredicate &predicate)
Definition: strtk.hpp:7249
unsigned char char_type
Definition: strtk.hpp:22889
void parse_checked(std::stack< T, Container > &stack) const
Definition: strtk.hpp:5918
void operator()(const std::pair< Iterator, Iterator > &r) const
Definition: strtk.hpp:2936
token_grid(const std::string &input_buffer, const std::size_t &input_buffer_size, const std::string &column_delimiters=",;|\t ", const std::string &row_delimiters="\n\r")
Definition: strtk.hpp:6081
multiple_delimiter_predicate(const Iterator begin, const Iterator end)
Definition: strtk.hpp:986
bool initialised() const
Definition: strtk.hpp:19753
std::deque< row_index_range_t > row_index_t
Definition: strtk.hpp:4961
bool operator()(const Sequence< T, Allocator > &sequence) const
Definition: strtk.hpp:7280
const_iterator_ref begin() const
Definition: strtk.hpp:2433
static unsigned int transform(const Range &key_range)
Definition: strtk.hpp:23090
bool operator()(const T(&data)[N], const bool write_length=false)
Definition: strtk.hpp:13421
sink_type< std::queue< T > > type
Definition: strtk.hpp:14333
std::size_t size() const
Definition: strtk.hpp:3682
std::size_t index_of(const std::string &pattern, const std::string &data)
Definition: strtk.hpp:2161
strtk_register_type_name(signed char) strtk_register_type_name(unsigned char) strtk_register_type_name(short) strtk_register_type_name(int) strtk_register_type_name(long) strtk_register_type_name(long long) strtk_register_type_name(unsigned short) strtk_register_type_name(unsigned int) strtk_register_type_name(unsigned long) strtk_register_type_name(unsigned long long int) strtk_register_type_name(double) strtk_register_type_name(float) strtk_register_type_name(long double) strtk_register_type_name(std
Definition: strtk.hpp:16947
virtual void compute_indices(const bloom_type &hash, std::size_t &bit_index, std::size_t &bit) const
Definition: strtk.hpp:19314
void swap_inplace(std::string &s, const std::size_t &i0, const std::size_t &i1)
Definition: strtk.hpp:14472
void operator()(const std::pair< Iterator, Iterator > &r)
Definition: strtk.hpp:2668
conv_to_lcase_impl & ref()
Definition: strtk.hpp:15368
void reset(const bool clear_buffer=false)
Definition: strtk.hpp:13391
hex_to_number_sink & operator=(const hex_to_number_sink &hns)
Definition: strtk.hpp:13875
range_to_ptr_type_iterator< T > range_to_ptr_type(T *pointer, std::size_t &insert_count)
Definition: strtk.hpp:2977
bool files_identical(const std::string &file_name1, const std::string &file_name2)
Definition: strtk.hpp:17485
bool match(const Iterator pattern_begin, const Iterator pattern_end, const Iterator data_begin, const Iterator data_end, const typename std::iterator_traits< Iterator >::value_type &zero_or_more, const typename std::iterator_traits< Iterator >::value_type &zero_or_one)
Definition: strtk.hpp:1783
tokenizer::iterator_type range_t
Definition: strtk.hpp:2466
inrange_impl(T &t, const T &low, const T &hi)
Definition: strtk.hpp:15234
void hash(const Iterator itr, std::size_t length, unsigned int &hash_value)
Definition: strtk.hpp:19629
std::size_t split_regex(const boost::regex &delimiter_expression, const InputIterator begin, const InputIterator end, OutputIterator out, const regex_match_mode::type mode=regex_match_mode::match_all)
Definition: strtk.hpp:3528
range_to_ptr_type_iterator & operator=(const std::string &s)
Definition: strtk.hpp:2923
std::size_t parse_line_n(std::ifstream &stream, const std::string &delimiters, const std::size_t &n, Sequence< T, Allocator > &sequence, const split_options::type &split_option=split_options::compress_delimiters)
Definition: strtk.hpp:9919
static bool cmp(ptr, ptr)
Definition: strtk.hpp:22631
void parse_checked(std::set< T, Comparator, Allocator > &set) const
Definition: strtk.hpp:5898
bool operator()(const Range &key_range, const Range &value_range)
Definition: strtk.hpp:23032
void insert(const std::string &key)
Definition: strtk.hpp:19074
filter_on_wildcard_match(const std::string &match_pattern, OutputPredicate &predicate, bool allow_through_on_match=true)
Definition: strtk.hpp:7137
combination_iterator(const std::size_t &k, iterator begin, iterator end, const bool sorted=true)
Definition: strtk.hpp:11775
#define strtk_parse_col_begin()
Definition: strtk.hpp:22328
container_adder(std::list< T, Allocator > &list)
Definition: strtk.hpp:8280
void parse_checked(std::priority_queue< T, Container, Comparator > &priority_queue) const
Definition: strtk.hpp:5926
inserter_with_valuetype_iterator< Set > inserter_with_valuetype(Set &set_)
Definition: strtk.hpp:2822
bool operator()(const Iterator begin, const Iterator end) const
Definition: strtk.hpp:7356
back_inserter_with_valuetype_iterator & operator*()
Definition: strtk.hpp:2738
bool type_to_string_converter_impl(const T &t, std::string &s, not_supported_type_tag)
Definition: strtk.hpp:16764
bool operator()(const std::string &str) const
Definition: strtk.hpp:7435
range_to_type_push_inserter_iterator & operator=(const range_to_type_push_inserter_iterator &it)
Definition: strtk.hpp:2649
bool clear_array(T(&a)[N], const T &t, const std::size_t &length=N)
Definition: strtk.hpp:22766
bool parse(T0 &t) const
Definition: strtk.hpp:5631
trim_impl< T > & ref()
Definition: strtk.hpp:15339
std::string as_string(const adapter< const unsigned char > &a)
Definition: strtk.hpp:933
#define register_stl_container2(C)
Definition: strtk.hpp:306
bool operator()(InputIterator begin, InputIterator end)
Definition: strtk.hpp:15387
bool operator()(const type &)
Definition: strtk.hpp:10697
void for_each_combination_conditional(Iterator begin, Iterator end, const std::size_t &size, Function function)
Definition: strtk.hpp:11512
std::size_t parse(const char *delimiters, Sequence< T, Allocator > &seq) const
Definition: strtk.hpp:17265
unsigned char uint8_t
Definition: strtk.hpp:13373
bool parse_with_index(const std::size_t &col, T &t) const
Definition: strtk.hpp:5501
void nth_combination_sequence(unsigned long long int n, const std::size_t &r, const std::size_t &k, OutputIterator out, const bool complete_index=true)
Definition: strtk.hpp:11623
std::size_t position() const
Definition: strtk.hpp:13399
bool twoway_bitwise_interleave(const unsigned char *begin1, const unsigned char *end1, const unsigned char *begin2, const unsigned char *end2, unsigned char *out)
Definition: strtk.hpp:4625
details::column_list_impl< 12 > column_list(const std::size_t &idx0, const std::size_t &idx1, const std::size_t &idx2, const std::size_t &idx3, const std::size_t &idx4, const std::size_t &idx5, const std::size_t &idx6, const std::size_t &idx7, const std::size_t &idx8, const std::size_t &idx9, const std::size_t &idx10, const std::size_t &idx11)
Definition: strtk.hpp:21219
ext_string & remove_leading(const std::string &removal_set)
Definition: strtk.hpp:17159
range_to_type_back_inserter_iterator & operator=(const std::pair< Iterator, Iterator > &r)
Definition: strtk.hpp:2503
bool ends_with(const InputIterator pattern_begin, const InputIterator pattern_end, const InputIterator begin, const InputIterator end)
Definition: strtk.hpp:2097
bool parse_with_index(const std::size_t &col0, const std::size_t &col1, const std::size_t &col2, const std::size_t &col3, const std::size_t &col4, const std::size_t &col5, const std::size_t &col6, const std::size_t &col7, const std::size_t &col8, const std::size_t &col9, T0 &t0, T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5, T6 &t6, T7 &t7, T8 &t8, T9 &t9) const
Definition: strtk.hpp:5355
bool is_letter(const char c)
Definition: strtk.hpp:14420
void construct(std::string &output, const std::string &delimiter, const T1 &t1, const T2 &t2, const T3 &t3, const T4 &t4, const T5 &t5, const T6 &t6, const T7 &t7, const T8 &t8, const T9 &t9, const T10 &t10, const T11 &t11, const T12 &t12)
Definition: strtk.hpp:10068
column_selector_base< column_selector_impl< T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11 >, 12 > csb_t
Definition: strtk.hpp:20971
bool operator()(const range_type &data, const bool ignore_failures=false)
Definition: strtk.hpp:22908
void reset(const bool clear_buffer=false)
Definition: strtk.hpp:12965
combination_iterator(const std::size_t &k, Sequence< T, Allocator > &seq, const bool sorted=true)
Definition: strtk.hpp:11792
bool for_each_permutation_conditional(Iterator begin, Iterator end, Function function)
Definition: strtk.hpp:11314
bool find_prefix(prefix< std::string::const_iterator, Value > &trie, const char *key)
Definition: strtk.hpp:18785
column_selector_base< Cli, N > csb_t
Definition: strtk.hpp:20854
combination_iterator & operator+=(const int inc)
Definition: strtk.hpp:11863
sink_type< std::priority_queue< T > > type
Definition: strtk.hpp:14335
bool parse(InputIterator begin, InputIterator end)
Definition: strtk.hpp:14300
bool operator==(const combination_iterator &itr) const
Definition: strtk.hpp:11877
multiple_delimiter_predicate(const T *d_begin, const T *d_end)
Definition: strtk.hpp:969
unsigned long long int minimum_size
Definition: strtk.hpp:18850
unsigned long long int random_seed
Definition: strtk.hpp:18867
static type create(const column_list_t &col_list, Sequence< T, Allocator > &seq)
Definition: strtk.hpp:21735
details::index_remover_impl< Allocator, Sequence > index_remover(const Sequence< std::size_t, Allocator > &sequence)
Definition: strtk.hpp:1112
void extract_column_checked(const std::size_t &index, std::multiset< T, Comparator, Allocator > &multiset) const
Definition: strtk.hpp:6203
#define strtk_parse_columns_impl(NN)
Definition: strtk.hpp:21900
void operator()(const Iterator begin, const Iterator end)
Definition: strtk.hpp:2948
static KType transform(const Range &)
Definition: strtk.hpp:23072
column_selector_impl(const column_list_t &column_list, T1 &t0, T1 &t1, T2 &t2)
Definition: strtk.hpp:21174
bool operator()(const InputIterator begin, const InputIterator end)
Definition: strtk.hpp:7092
bool operator()(const std::pair< InputIterator, InputIterator > &r) const
Definition: strtk.hpp:20135
bool in_use() const
Definition: strtk.hpp:23303
bool operator()(const Iterator begin, const Iterator end) const
Definition: strtk.hpp:7400
combination_iterator(iterator end)
Definition: strtk.hpp:11820
fill_array_impl & set_data(char *data)
Definition: strtk.hpp:15449
bool join_row(const std::size_t &row, Predicate predicate, const std::string &delimiter, std::string &result)
Definition: strtk.hpp:6651
double effective_fpp() const
Definition: strtk.hpp:19165
std::pair< Iterator, Iterator > type
Definition: strtk.hpp:14544
sink_type & operator()(Container &container, const std::string &delimiters="", const split_options::type &split_option=split_options::compress_delimiters)
Definition: strtk.hpp:14288
const unsigned char * ptr
Definition: strtk.hpp:22625
bool operator()(const T &input, const std::size_t &size, const padding_mode pmode, const char padding= ' ')
Definition: strtk.hpp:13609
optimal_parameters_t optimal_parameters
Definition: strtk.hpp:18902
iexpect_impl & ref()
Definition: strtk.hpp:15182
sink_type & count(const std::size_t &element_count=std::numeric_limits< std::size_t >::max())
Definition: strtk.hpp:14282
base64_to_number_sink & operator=(const std::string &s)
Definition: strtk.hpp:13983
void set_value(const std::string &s)
Definition: strtk.hpp:15187
static bool execute(InputIterator begin, InputIterator end, const std::string &rem_chars, std::size_t mode, std::string &t)
Definition: strtk.hpp:15301
range_to_ptr_type_iterator operator++(int)
Definition: strtk.hpp:2965
std::pair< iterator_t, iterator_t > range_t
Definition: strtk.hpp:4958
column_selector_impl< T, T, T, T, T, T, T, T, T > type
Definition: strtk.hpp:21772
bool operator()(const T &d) const
Definition: strtk.hpp:1013
bool parse(std::set< T, Comparator, Allocator > &set) const
Definition: strtk.hpp:5813
std::size_t row_count() const
Definition: strtk.hpp:6117
csii_t & operator=(const std::pair< Iterator, Iterator > &r)
Definition: strtk.hpp:21866
std::string remove_duplicates(const std::string &str)
Definition: strtk.hpp:1354
bool operator()(InputIterator begin, InputIterator end)
Definition: strtk.hpp:15360
col_range_t all_columns() const
Definition: strtk.hpp:5291
counting_back_inserter_iterator< T > counting_back_inserter(std::size_t &counter_)
Definition: strtk.hpp:3047
void assign(const std::string &s) const
Definition: strtk.hpp:2415
bool find(const key_iterator_t begin, const key_iterator_t end, value_t &v) const
Definition: strtk.hpp:18692
void min_max_of_cont(const Sequence< T, Allocator > &sequence, T &min_value, T &max_value)
Definition: strtk.hpp:4000
const std::string::value_type * string_iterator_type
Definition: strtk.hpp:2459
void reverse(std::string &s)
Definition: strtk.hpp:22826
multiple_char_delimiter_predicate(const std::string &s)
Definition: strtk.hpp:1040
inserter_with_valuetype_iterator & operator=(const typename Set::value_type &v)
Definition: strtk.hpp:2790
scoped_timer(double &time_value)
Definition: strtk.hpp:23326
std::size_t amount_written() const
Definition: strtk.hpp:13409
const char * first_non_repeated_char(const char *begin, const char *end)
Definition: strtk.hpp:4105
range_to_type_back_inserter_iterator & operator*()
Definition: strtk.hpp:2533
#define strtk_parse_col_token_seq(Index)
Definition: strtk.hpp:21897
unsigned long long int table_size_
Definition: strtk.hpp:19441
void set_pattern(const std::string &s)
Definition: strtk.hpp:15219
void random_permutation(const Iterator begin, const Iterator end, RandomNumberGenerator &rng, OutputIterator out)
Definition: strtk.hpp:11096
column_list_impl< 12 > column_list_t
Definition: strtk.hpp:20972
bool operator()(const std::string &str) const
Definition: strtk.hpp:7479
void insert(const key_iterator_t begin, const key_iterator_t end, const value_t &v)
Definition: strtk.hpp:18663
std::size_t parse_n(const std::size_t &n, Sequence< T, Allocator > &sequence) const
Definition: strtk.hpp:5849
trim_impl(const std::size_t mode, T &t, const std::string &rem_chars=" ")
Definition: strtk.hpp:15325
adapter(T *const begin, const std::size_t length)
Definition: strtk.hpp:847
std::size_t size() const
Definition: strtk.hpp:5311
range_to_type_push_inserter_iterator & operator++()
Definition: strtk.hpp:2680
std::string center(const std::size_t &width, const T &t)
Definition: strtk.hpp:14390
range_to_type_back_inserter_iterator(const range_to_type_back_inserter_iterator &it)
Definition: strtk.hpp:2489
bool match_atleast_n_consecutive_values(const std::size_t n, Predicate p, Iterator itr, const Iterator end)
Definition: strtk.hpp:14680
void join_if(std::string &output, const std::string &delimiter, Predicate predicate, const InputIterator begin, const InputIterator end)
Definition: strtk.hpp:10384
std::size_t write_to_text_file(std::ostream &stream, const Sequence< T, Allocator > &sequence, const std::string &delimiter="")
Definition: strtk.hpp:594
column_selector_impl< T, T, T, T > type
Definition: strtk.hpp:21667
bool native_to_be(const T &input)
Definition: strtk.hpp:13581
bool join_column(const std::size_t &col, const row_range_t &row_range, Predicate predicate, const std::string &delimiter, std::string &result) const
Definition: strtk.hpp:6728
strtk_register_iostream_precision(float) strtk_register_iostream_precision(double) strtk_register_iostream_precision(long double) template< typename Iterator
void operator()(const std::pair< Iterator, Iterator > &range) const
Definition: strtk.hpp:7189
std::string remove_duplicates_inplace(std::string &str)
Definition: strtk.hpp:1372
std::size_t for_each_row(const row_range_t &row_range, Function f) const
Definition: strtk.hpp:6816
bool operator()(const std::set< T, Comparator, Allocator > &set)
Definition: strtk.hpp:13523
bool operator()(const Iterator begin, const Iterator end) const
Definition: strtk.hpp:7444
range_to_type_back_inserter_iterator & operator++()
Definition: strtk.hpp:2538
bool register_keyvalue(const key_type &key, T &t)
Definition: strtk.hpp:23148
static type create(const column_list_t &col_list, std::list< T, Allocator > &list)
Definition: strtk.hpp:21615
trie::prefix< KeyIterator, ValueType > std_string
Definition: strtk.hpp:18797
conv_to_ucase_impl & ref()
Definition: strtk.hpp:15395
void cut(const std::size_t &r0, const std::size_t &r1, const InputIterator begin, InputIterator end, OutputIterator out)
Definition: strtk.hpp:10834
void insert(const InputIterator begin, const InputIterator end)
Definition: strtk.hpp:19085
std::size_t for_each_column(Function f) const
Definition: strtk.hpp:5950
bool operator()(T *&data, uint32_t &length, const bool read_length=true)
Definition: strtk.hpp:13026
void remove_pattern(const std::string &s, const std::string &p, std::string &n)
Definition: strtk.hpp:1769
column_selector_impl< T, T, T, T, T > type
Definition: strtk.hpp:21688
std::size_t split_on_consecutive(const std::size_t n, Predicate p, char *begin, char *end, OutputIterator out, const bool stateful_predicate=false)
Definition: strtk.hpp:14796
std::size_t parse_n_stl_container_proxy(const InputIterator begin, const InputIterator end, const std::string &delimiters, const std::size_t &n, Sequence< T, Allocator > &sequence, const split_options::type &split_option=split_options::compress_delimiters)
Definition: strtk.hpp:14179
bool operator()(const T *data, const uint8_t &length, const bool write_length=true)
Definition: strtk.hpp:13467
std::pair< Iterator, Iterator > range_type
Definition: strtk.hpp:11773
void delete_all(std::multiset< T *, Comparator, Allocator > &cont)
Definition: strtk.hpp:20345
static type create(const column_list_t &col_list, Sequence< T, Allocator > &seq)
Definition: strtk.hpp:21651
bool parse_with_index(const std::size_t &col0, const std::size_t &col1, T0 &t0, T1 &t1) const
Definition: strtk.hpp:5492
trie::prefix< char *, ValueType > char_ptr
Definition: strtk.hpp:18798
#define strtk_register_sink_type_tag(T)
Definition: strtk.hpp:15770
static type create(const column_list_t &col_list, std::list< T, Allocator > &list)
Definition: strtk.hpp:21636
#define parse_digit_2
details::range_type< Iterator >::type find_n_consecutive(const std::size_t n, find_type::type type, find_mode::type mode, typename details::range_type< Iterator >::type range)
Definition: strtk.hpp:14721
bool operator!() const
Definition: strtk.hpp:6107
std::size_t amount_read()
Definition: strtk.hpp:12983
static void process(Iterator, T &)
Definition: strtk.hpp:12223
strtk_register_rand_int_type_tag(char) strtk_register_rand_int_type_tag(unsigned char) strtk_register_rand_int_type_tag(short) strtk_register_rand_int_type_tag(int) strtk_register_rand_int_type_tag(long) strtk_register_rand_int_type_tag(unsigned short) strtk_register_rand_int_type_tag(unsigned int) strtk_register_rand_int_type_tag(unsigned long) strtk_register_rand_real_type_tag(float) strtk_register_rand_real_type_tag(double) strtk_register_rand_real_type_tag(long double) template< typename T
push_inserter_iterator< Container > push_inserter(Container &c)
Definition: strtk.hpp:2876
bool operator()(T(&output)[N])
Definition: strtk.hpp:13227
range_to_type_inserter_iterator & operator=(const std::pair< Iterator, Iterator > &r)
Definition: strtk.hpp:2588
bool join_column(const std::size_t &col, const row_range_t &row_range, const std::string &delimiter, std::string &result) const
Definition: strtk.hpp:6690
std::size_t load_from_text_file(std::istream &stream, Sequence< T, Allocator > &sequence, const std::size_t &buffer_size=one_kilobyte)
Definition: strtk.hpp:404
range_to_type_back_inserter_iterator(Sequence &sequence)
Definition: strtk.hpp:2485
bool operator()(const T &d) const
Definition: strtk.hpp:951
hex_to_string_sink & operator=(const std::pair< InputIterator, InputIterator > &s)
Definition: strtk.hpp:14061
bool rewind(const std::size_t &n_bytes)
Definition: strtk.hpp:12988
unsigned int maximum_number_of_hashes
Definition: strtk.hpp:18855
void nth_permutation_sequence(std::size_t n, const std::size_t k, OutputIterator out)
Definition: strtk.hpp:11700
void convert_to_lowercase(unsigned char *begin, unsigned char *end)
Definition: strtk.hpp:4580
std::size_t element_count() const
Definition: strtk.hpp:19160
push_inserter_iterator< Container > & operator=(typename Container::const_reference v)
Definition: strtk.hpp:2849
bool all_digits_check(Iterator begin, Iterator end)
Definition: strtk.hpp:12603
void assign(T &t)
Definition: strtk.hpp:20146
column_selector_impl< T, T, T > type
Definition: strtk.hpp:21646
build_string(const std::size_t &initial_size=64)
Definition: strtk.hpp:10526
offset_predicate(const int offset_list[], const bool rotate=false)
Definition: strtk.hpp:3664
void bitwise_transform(const bitwise_operation::type &operation, const unsigned char *begin1, const unsigned char *end1, const unsigned char *begin2, unsigned char *out)
Definition: strtk.hpp:4731
std::size_t raw_length(const std::size_t &column_index) const
Definition: strtk.hpp:5328
std::size_t parse_stl_container_proxy(const InputIterator begin, const InputIterator end, const std::string &delimiters, Sequence< T, Allocator > &sequence, const split_options::type &split_option=split_options::compress_delimiters)
Definition: strtk.hpp:14103
details::column_list_impl< N > column_list_t
Definition: strtk.hpp:21838
bool string_to_type_converter(const Iterator begin, const Iterator end, T &t)
Definition: strtk.hpp:324
container_adder(std::set< T, Comparator, Allocator > &set)
Definition: strtk.hpp:8285
hex_to_string_sink(std::string &s)
Definition: strtk.hpp:14043
#define register_stl_container1(C)
Definition: strtk.hpp:303
unsigned short uint16_t
Definition: strtk.hpp:13372
void enforce_column_count(const row_range_t &row_range, const std::size_t &column_count)
Definition: strtk.hpp:6479
#define strtk_register_supported_iterator_type(T)
Definition: strtk.hpp:15728
void generate_random_values(const std::size_t &count, const T &min, const T &max, OutputIterator out, const std::size_t &seed=magic_seed, const std::size_t &pregen=0)
Definition: strtk.hpp:11064
sink_type< std::deque< T > > type
Definition: strtk.hpp:14329
unsigned char cell_type
Definition: strtk.hpp:18961
counting_back_inserter_iterator operator++(int)
Definition: strtk.hpp:3036
bool operator()(strtk::binary::reader &reader)
Definition: strtk.hpp:18869
details::conv_to_ucase_impl as_ucase(std::string &s)
Definition: strtk.hpp:15513
static bool cmp(ptr c1, ptr c2)
Definition: strtk.hpp:22637
bool extract_column_checked(const row_range_t &row_range, const std::size_t &index, OutputIterator out) const
Definition: strtk.hpp:6155
bool parse(T0 &t0, T1 &t1, T2 &t2, T3 &t3, T4 &t4) const
Definition: strtk.hpp:5592
counting_back_inserter_iterator & operator*()
Definition: strtk.hpp:3026
hex_to_number_sink(const hex_to_number_sink &hns)
Definition: strtk.hpp:13870
static bool execute(InputIterator begin, InputIterator end, const std::string &rem_chars, std::size_t mode, Type &t)
Definition: strtk.hpp:15278
tokenizer_iterator< Iterator, DelimiterPredicate > iterator
Definition: strtk.hpp:2374
details::inrange_impl< T > inrange(T &t, const T0 &low, const T1 &hi)
Definition: strtk.hpp:15485
std::size_t parse(const std::string &delimiters, Sequence< T, Allocator > &seq) const
Definition: strtk.hpp:17257
void generate_random_data(unsigned char *data, std::size_t length, unsigned int pre_gen_cnt=0, unsigned int seed=magic_seed)
Definition: strtk.hpp:10943
multiple_delimiter_predicate(const T d[], const std::size_t &length)
Definition: strtk.hpp:977
offset_predicate< 12 > offsets(const int &v1, const int &v2, const int &v3, const int &v4, const int &v5, const int &v6, const int &v7, const int &v8, const int &v9, const int &v10, const int &v11, const int &v12, const bool &rotate=false)
Definition: strtk.hpp:3704
functional_inserter_iterator & operator=(const T &t)
Definition: strtk.hpp:3079
hex_to_number_sink & operator=(const std::pair< InputIterator, InputIterator > &s)
Definition: strtk.hpp:13883
column_selector_impl(const column_list_t &column_list, T1 &t0, T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5, T6 &t6)
Definition: strtk.hpp:21093
functional_inserter_iterator(Function function)
Definition: strtk.hpp:3061
token_grid(const unsigned char *input_buffer, const std::size_t &input_buffer_size, const token_grid::options &options)
Definition: strtk.hpp:5992
static bool cmp(ptr c1, ptr c2)
Definition: strtk.hpp:22643
multiple_char_delimiter_predicate(const Iterator begin, const Iterator end)
Definition: strtk.hpp:1035
filter_on_match(const std::string *begin, const std::string *end, OutputPredicate predicate, bool case_insensitive, bool allow_through_on_match=true)
Definition: strtk.hpp:7177
void fill(Sequence< T, Allocator > &seq, const T &t)
Definition: strtk.hpp:22861
bool operator()(std::string &output)
Definition: strtk.hpp:13058
const unsigned char * iterator_t
Definition: strtk.hpp:4956
bool load(unsigned char *buffer, const std::size_t buffer_size, const token_grid::options &options)
Definition: strtk.hpp:6864
ext_string & remove_trailing(const Predicate &p)
Definition: strtk.hpp:17171
bool parse(const col_range_t &range, std::set< T, Comparator, Allocator > &set) const
Definition: strtk.hpp:5694
#define strtk_register_stdstring_range_type_tag(T)
Definition: strtk.hpp:15767
void replicate_inplace(const std::size_t &n, std::string &str)
Definition: strtk.hpp:10578
ignore_token & operator=(const std::string &)
Definition: strtk.hpp:13836
push_inserter_iterator & operator=(const push_inserter_iterator &itr)
Definition: strtk.hpp:2840
void iota(Iterator begin, Iterator end, T value)
Definition: strtk.hpp:10746
bool add(InputIterator begin, InputIterator end) const
Definition: strtk.hpp:8310
unsigned int inserted_element_count_
Definition: strtk.hpp:19444
std::string translate(const translation_table &trans_table, const std::string &s)
Definition: strtk.hpp:10930
void numeric_convert(Iterator itr, T &t, const bool digit_check=false)
Definition: strtk.hpp:12649
bool operator==(const value &v) const
Definition: strtk.hpp:20103
push_inserter_iterator< Container > & operator++()
Definition: strtk.hpp:2860
static type create(const column_list_t &col_list, std::list< T, Allocator > &list)
Definition: strtk.hpp:21741
bool operator()(const Iterator begin, const Iterator end)
Definition: strtk.hpp:18528
void replicate(const std::size_t &n, const std::string &str, std::string &output)
Definition: strtk.hpp:10558
bool operator()(InputIterator begin, InputIterator end)
Definition: strtk.hpp:15334
unsigned int minimum_number_of_hashes
Definition: strtk.hpp:18854
options & set_row_split_option(const split_options::type &option)
Definition: strtk.hpp:5233
token_grid(const std::string &file_name, const token_grid::options &options)
Definition: strtk.hpp:5980
bool operator()(std::ifstream &stream, const std::size_t &length)
Definition: strtk.hpp:13172
bool operator()(const unsigned char &c) const
Definition: strtk.hpp:1045
ext_string operator-(const ext_string &s, const std::string &pattern)
Definition: strtk.hpp:17344
std::size_t find_all(const Iterator pattern_begin, const Iterator pattern_end, const Iterator begin, const Iterator end, OutputIterator out)
Definition: strtk.hpp:1933
std::iterator_traits< Iterator >::value_type value_type
Definition: strtk.hpp:2372
ext_string & remove_trailing(const std::string &removal_set)
Definition: strtk.hpp:17178
bool parse_with_index(const std::size_t &col0, const std::size_t &col1, const std::size_t &col2, const std::size_t &col3, const std::size_t &col4, const std::size_t &col5, const std::size_t &col6, const std::size_t &col7, T0 &t0, T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5, T6 &t6, T7 &t7) const
Definition: strtk.hpp:5401
void clear(std::priority_queue< T, Container, Comparator > &priority_queue)
Definition: strtk.hpp:20832
bool operator()(const std::pair< Iterator, Iterator > &range) const
Definition: strtk.hpp:7362
bool operator==(const T &t)
Definition: strtk.hpp:19722
static type create(const column_list_t &col_list, std::list< T, Allocator > &list)
Definition: strtk.hpp:21804
bloom_type hash_ap(const unsigned char *begin, std::size_t remaining_length, bloom_type hash) const
Definition: strtk.hpp:19397
bool string_to_type_converter_impl(Iterator &itr, const Iterator end, strtk::util::semantic_action_impl &result, semantic_action_type_tag)
Definition: strtk.hpp:20007
column_selector_impl< T, T, T, T, T, T, T, T, T, T > type
Definition: strtk.hpp:21793
bool operator()(std::ifstream &stream)
Definition: strtk.hpp:13179
void replace(const typename std::iterator_traits< Iterator >::value_type &c1, const typename std::iterator_traits< Iterator >::value_type &c2, const Iterator begin, const Iterator end)
Definition: strtk.hpp:1581
range_t token(const unsigned int &row, const std::size_t &col) const
Definition: strtk.hpp:6132
bool operator()(T *&data, uint64_t &length, const bool read_length=true)
Definition: strtk.hpp:13046
std::size_t remove_consecutives_inplace(Predicate predicate, Iterator begin, Iterator end)
Definition: strtk.hpp:1186
semantic_action_impl & ref()
Definition: strtk.hpp:19917
container_adder(std::deque< T, Allocator > &deq)
Definition: strtk.hpp:8275
counting_back_inserter_iterator & operator=(const T &)
Definition: strtk.hpp:3015
bool is_all_letters(const std::string &s)
Definition: strtk.hpp:14452
iterator end() const
Definition: strtk.hpp:857
fill_array_impl(unsigned char *data, const std::size_t &size)
Definition: strtk.hpp:15409
void combine_discontinuous(Iterator first1, Iterator last1, typename std::iterator_traits< Iterator >::difference_type d1, Iterator first2, Iterator last2, typename std::iterator_traits< Iterator >::difference_type d2, Function &f, typename std::iterator_traits< Iterator >::difference_type d=0)
Definition: strtk.hpp:11355
#define strtk_register_set_type_name(Type)
Definition: strtk.hpp:17041
hex_to_string_sink & operator=(const std::string &s)
Definition: strtk.hpp:14079
functional_inserter_iterator & operator*()
Definition: strtk.hpp:3091
void as_string(std::string &out) const
Definition: strtk.hpp:5347
sink_type(Container &container, const std::string &delimiters, const split_options::type &split_option=split_options::compress_delimiters)
Definition: strtk.hpp:14274
std::size_t select_k_randomly(const Iterator begin, const Iterator end, const std::size_t k, OutputIterator out, RandomNumberGenerator &rng)
Definition: strtk.hpp:11193
Tag bool string_to_type_converter_impl(Iterator &begin, const Iterator end, T &t, not_supported_type_tag)
Definition: strtk.hpp:15950
column_selector_base< column_selector_impl< T0, T1, T2 >, 3 > csb_t
Definition: strtk.hpp:21171
range_type current_combination_
Definition: strtk.hpp:11894
static type create(const column_list_t &col_list, Sequence< T, Allocator > &seq)
Definition: strtk.hpp:21630
sink_type< std::stack< T > > type
Definition: strtk.hpp:14334
sequence_t::const_iterator itr_
Definition: strtk.hpp:1103
std::size_t hash_count()
Definition: strtk.hpp:19307
bool operator()(InputIterator begin, InputIterator end) const
Definition: strtk.hpp:20126
std::size_t accumulate_column(const std::size_t &col, const row_range_t &row_range, T &result) const
Definition: strtk.hpp:6549
back_inserter_with_valuetype_iterator & operator=(const typename Sequence::value_type &v)
Definition: strtk.hpp:2727
range_to_type_inserter_iterator< Set > range_to_type_inserter(Set &set)
Definition: strtk.hpp:2625
#define strtk_register_rand_real_type_tag(T)
Definition: strtk.hpp:10985
bool operator()(InputIterator begin, InputIterator end)
Definition: strtk.hpp:15174
bool operator()(const std::set< T, Comparator, Allocator > &set) const
Definition: strtk.hpp:7378
void operator()(const Iterator begin, const Iterator end)
Definition: strtk.hpp:2528
unsigned int uint32_t
Definition: strtk.hpp:13371
std::ostream & operator<<(std::ostream &out, const LogHistogram &hist)
ext_string(const ext_string &es)
Definition: strtk.hpp:17086
const T & value() const
Definition: strtk.hpp:19768
column_selector_iterator_impl< InputIterator, N > csii_t
Definition: strtk.hpp:21837
bool parse_line(std::ifstream &stream, const std::string &delimiters, T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5, T6 &t6, T7 &t7, T8 &t8, T9 &t9, T10 &t10, T11 &t11, T12 &t12)
Definition: strtk.hpp:9531
key_map< std::string > stringkey_map
Definition: strtk.hpp:23165
details::trim_impl< T > trim_leading(const std::string &rem_chars, T &t)
Definition: strtk.hpp:15497
container_adder(std::stack< T, Container > &stack)
Definition: strtk.hpp:8305
std::size_t split_on_consecutive_n(const std::size_t &n, const std::size_t &m, const find_type::type type, const find_mode::type mode, char *begin, char *end, OutputIterator out)
Definition: strtk.hpp:14895
void make_value_list(const std::multimap< Key, T, Comparator, MapAllocator > &map, const Key &key, Sequence< T, SequenceAllocator > &sequence)
Definition: strtk.hpp:20273
bool parse(T0 &t0, T1 &t1) const
Definition: strtk.hpp:5623
bool operator()(const std::set< T, Comparator, Allocator > &set) const
Definition: strtk.hpp:7333
void reset() const
Definition: strtk.hpp:3677
filter(const filter &filter)
Definition: strtk.hpp:18991
void join(std::string &output, const std::string &delimiter, const InputIterator begin, const InputIterator end)
Definition: strtk.hpp:10244
void for_each_combination(Iterator begin, Iterator end, const std::size_t &size, Function function)
Definition: strtk.hpp:11496
std::size_t accumulate_row(const std::size_t &row, T &result) const
Definition: strtk.hpp:6525
bool parse(const col_range_t &range, std::stack< T, Container > &stack) const
Definition: strtk.hpp:5759
bool parse(std::multiset< T, Comparator, Allocator > &multiset) const
Definition: strtk.hpp:5821
bool extract_column(const row_range_t &row_range, const std::size_t &index0, const std::size_t &index1, const std::size_t &index2, const std::size_t &index3, OutputIterator0 out0, OutputIterator1 out1, OutputIterator2 out2, OutputIterator3 out3) const
Definition: strtk.hpp:6293
KeyValidator key_validator_type
Definition: strtk.hpp:23120
void insert_inplace(std::string &s, const std::size_t &index, const char c)
Definition: strtk.hpp:14501
static type create(const column_list_t &col_list, std::list< T, Allocator > &list)
Definition: strtk.hpp:21699
unsigned long long int random_seed_
Definition: strtk.hpp:19445
static ext_string all_lowercase_letters()
Definition: strtk.hpp:17295
static bool cmp(ptr c1, ptr c2)
Definition: strtk.hpp:22640
bool parse(std::priority_queue< T, Container, Comparator > &priority_queue) const
Definition: strtk.hpp:5841
range_type< Iterator >::type find_exactly_n_consecutive_values(const std::size_t n, Predicate p, Iterator itr, const Iterator end, const bool stateful_predicate=false)
Definition: strtk.hpp:14548
void bracketize(std::string &output, const std::string &pre, const std::string &post, const InputIterator begin, const InputIterator end)
Definition: strtk.hpp:10591
bool compress(const double &percentage)
Definition: strtk.hpp:19485
column_selector_base< column_selector_impl< T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10 >, 11 > csb_t
Definition: strtk.hpp:20997
filter_non_empty_range(OutputIterator out)
Definition: strtk.hpp:7114
void operator()(const typename Sequence::value_type &v)
Definition: strtk.hpp:2733
void for_each_permutation(Iterator begin, Iterator end, Function function)
Definition: strtk.hpp:11304
fill_array_impl & set_data(unsigned char *data)
Definition: strtk.hpp:15443
column_selector_impl< T, T, T, T, T, T, T > type
Definition: strtk.hpp:21730
counting_back_inserter_iterator(std::size_t &counter)
Definition: strtk.hpp:2998
bool is_digit(const char c)
Definition: strtk.hpp:14435
bool extract_column(const std::size_t &index, OutputIterator out) const
Definition: strtk.hpp:6231
bool register_keyvalue(const key_type &key, T &t)
Definition: strtk.hpp:23047
#define strtk_register_base64_type_tag(T)
Definition: strtk.hpp:15725
std::size_t hamming_distance(const unsigned char *begin1, const unsigned char *end1, const unsigned char *begin2, const unsigned char *end2)
Definition: strtk.hpp:4889
trie::prefix< KeyIterator, ValueType > type
Definition: strtk.hpp:18796
range_type operator*() const
Definition: strtk.hpp:11872
void insert(const char *data, const std::size_t &length)
Definition: strtk.hpp:19079
adapter< const char > string
Definition: strtk.hpp:900
void insert(const unsigned char *key_begin, const std::size_t &length)
Definition: strtk.hpp:19055
bool is_letter_or_digit(const char c)
Definition: strtk.hpp:14447
bool join_column(const std::size_t &col, const std::string &delimiter, std::string &result) const
Definition: strtk.hpp:6720
attribute & operator=(const T &t)
Definition: strtk.hpp:19715
row_range_t all_rows() const
Definition: strtk.hpp:6149
base64_to_number_sink(const base64_to_number_sink &bns)
Definition: strtk.hpp:13971
ignore_token & operator=(const std::pair< InputIterator, InputIterator > &)
Definition: strtk.hpp:13831
std::size_t for_each_line(std::istream &stream, Function function, const std::size_t &buffer_size=one_kilobyte)
Definition: strtk.hpp:94
#define strtk_register_sequence_iterator_type(sequence)
Definition: strtk.hpp:15800
InputIterator copy_until(Predicate predicate, const InputIterator begin, const InputIterator end, OutputIterator out)
Definition: strtk.hpp:785
range_to_ptr_type_iterator & operator*()
Definition: strtk.hpp:2955
std::size_t for_each_line_n_conditional(std::istream &stream, const std::size_t &n, Function function, const std::size_t &buffer_size=one_kilobyte)
Definition: strtk.hpp:172
token_grid(const unsigned char *input_buffer, const std::size_t &input_buffer_size, const std::string &column_delimiters=",|;\t", const std::string &row_delimiters="\n\r")
Definition: strtk.hpp:6047
static type create(const column_list_t &col_list, Sequence< T, Allocator > &seq)
Definition: strtk.hpp:21693
ext_string operator*(const std::size_t &n, const ext_string &s)
Definition: strtk.hpp:17322
std::iterator_traits< KeyIterator >::value_type key_value_t
Definition: strtk.hpp:18652
functional_inserter_iterator operator++(int)
Definition: strtk.hpp:3101
details::trim_impl< T > trim(const std::string &rem_chars, T &t)
Definition: strtk.hpp:15491
bool is_all_digits(const std::string &s)
Definition: strtk.hpp:14462
bool match_exactly_n_consecutive_values(const std::size_t n, Predicate p, Iterator itr, const Iterator end)
Definition: strtk.hpp:14656
std::size_t inserter(Inserter ins, const InputIterator begin, const InputIterator end, OutputIterator out)
Definition: strtk.hpp:10723
bool operator()(const std::string &input)
Definition: strtk.hpp:13482
const T & operator[](const std::size_t &index) const
Definition: strtk.hpp:872
functional_inserter_iterator< Function > functional_inserter(Function function)
Definition: strtk.hpp:3112
bool contains(const std::string &key) const
Definition: strtk.hpp:19115
unsigned char * bit_table_
Definition: strtk.hpp:19439
ext_string & remove_leading(const Predicate &p)
Definition: strtk.hpp:17152
column_selector_base< column_selector_impl< T0, T1, T2, T3 >, 4 > csb_t
Definition: strtk.hpp:21153
bool type_to_string_converter_impl(const strtk::util::value &v, std::string &result, value_type_tag)
Definition: strtk.hpp:22692
bool parse(T0 &t0, T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5, T6 &t6, T7 &t7, T8 &t8) const
Definition: strtk.hpp:5529
bool operator()(const InputIterator begin, const InputIterator end)
Definition: strtk.hpp:8322
std::vector< bloom_type > salt_
Definition: strtk.hpp:19438
bool is_lowercase_letter(const char c)
Definition: strtk.hpp:14425
void push_back(std::multiset< T, Comparator, Allocator > &set, const T &v1)
Definition: strtk.hpp:20783
bool parse_with_index(const std::size_t &col0, const std::size_t &col1, const std::size_t &col2, const std::size_t &col3, const std::size_t &col4, const std::size_t &col5, const std::size_t &col6, T0 &t0, T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5, T6 &t6) const
Definition: strtk.hpp:5421
bool memcmp_n(details::ptr c1, details::ptr c2)
Definition: strtk.hpp:22673
ext_string(const char *s)
Definition: strtk.hpp:17078
void parse_checked(std::queue< T, Container > &queue) const
Definition: strtk.hpp:5912
std::size_t for_each_row(Function f) const
Definition: strtk.hpp:6830
std::string & as_string()
Definition: strtk.hpp:17112
base64_to_number_sink & operator=(const std::pair< InputIterator, InputIterator > &s)
Definition: strtk.hpp:14000
bool operator()(const Iterator begin, const Iterator end) const
Definition: strtk.hpp:7311
void sort(std::string &s)
Definition: strtk.hpp:1777
range_type< Iterator >::type find_n_consecutive_values(const std::size_t n, find_mode::type mode, Predicate p, Iterator itr, const Iterator end)
Definition: strtk.hpp:14641
iterator begin() const
Definition: strtk.hpp:852
void extract_column_checked(const std::size_t &index, Sequence< T, Allocator > &sequence) const
Definition: strtk.hpp:6185
bool operator()(std::vector< T, Allocator > &vec)
Definition: strtk.hpp:13112
interval_inserter(const std::size_t &interval, const T &t)
Definition: strtk.hpp:10691
bool parse(const col_range_t &range, std::multiset< T, Comparator, Allocator > &multiset) const
Definition: strtk.hpp:5717
bool operator()(InputIterator begin, InputIterator end)
Definition: strtk.hpp:15142
bool operator()(const Sequence< T, Allocator > &seq)
Definition: strtk.hpp:13490
const column_list_t & column_list_
Definition: strtk.hpp:20951
combination_iterator(const std::size_t &k, std::string &str, const bool sorted=true)
Definition: strtk.hpp:11806
std::size_t parse_n(const InputIterator begin, const InputIterator end, const std::string &delimiters, const std::size_t &n, Sequence< T, Allocator > &sequence, const split_options::type &split_option=split_options::compress_delimiters)
Definition: strtk.hpp:8716
range_to_type_back_inserter_iterator & operator=(const std::string &s)
Definition: strtk.hpp:2511
range_to_ptr_type_iterator & operator++()
Definition: strtk.hpp:2960
static type create(const column_list_t &col_list, std::list< T, Allocator > &list)
Definition: strtk.hpp:21678
void min_max_of_range(const InputIterator begin, const InputIterator end, typename std::iterator_traits< InputIterator >::value_type &min_value, typename std::iterator_traits< InputIterator >::value_type &max_value)
Definition: strtk.hpp:3981
unsigned long long int raw_table_size_
Definition: strtk.hpp:19442
unsigned char uint8_t
Definition: strtk.hpp:12946
std::size_t remove_trailing(Predicate predicate, Iterator begin, Iterator end)
Definition: strtk.hpp:1378
void parse_checked(Sequence< T, Allocator > &sequence) const
Definition: strtk.hpp:5890
bool parse(const InputIterator begin, const InputIterator end, const std::string &delimiters, T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5, T6 &t6, T7 &t7, T8 &t8, T9 &t9, T10 &t10, T11 &t11, T12 &t12)
Definition: strtk.hpp:7489
virtual unsigned long long int size() const
Definition: strtk.hpp:19155
node< KeyIterator, value_t > node_t
Definition: strtk.hpp:18655
details::column_selector_impl< T0, T1, T2, T3, T4, T5, T6, T7, T8, T9 > column_selector(const details::column_list_impl< 11 > &col_list, T0 &t0, T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5, T6 &t6, T7 &t7, T8 &t8, T9 &t9, T10 &t10, T11 &t11)
Definition: strtk.hpp:21443
tokenizer(const Iterator begin, const Iterator end, const DelimiterPredicate &predicate, const tokenize_options::type tokenize_options=tokenize_options::default_mode)
Definition: strtk.hpp:2379
bool operator()(const std::vector< T, Allocator > &vec)
Definition: strtk.hpp:13509
char_type pair_block_delimiter
Definition: strtk.hpp:22880
std::size_t remove_inplace(Predicate predicate, Iterator begin, Iterator end)
Definition: strtk.hpp:1118
container_adder(std::vector< T, Allocator > &vec)
Definition: strtk.hpp:8270
short_string_impl< size_type > & set(std::string &str)
Definition: strtk.hpp:13779
bool imatch_char(const char c1, const char c2)
Definition: strtk.hpp:1854
bool write_to_file(const std::string &file_name) const
Definition: strtk.hpp:19233
details::iexpect_impl iexpect(const std::string &s)
Definition: strtk.hpp:15474
range_to_ptr_type_iterator & operator=(const std::pair< Iterator, Iterator > &r)
Definition: strtk.hpp:2911
filter(const parameters &p)
Definition: strtk.hpp:18976
Definition: mongoose.c:392
inserter_with_valuetype_iterator(const inserter_with_valuetype_iterator &itr)
Definition: strtk.hpp:2777
reader(T *buffer, const std::size_t &buffer_length)
Definition: strtk.hpp:12950
std::size_t min_column_count() const
Definition: strtk.hpp:6122
virtual bool contains(const unsigned char *key_begin, const std::size_t length) const
Definition: strtk.hpp:19094
semantic_action_impl(const Function &f)
Definition: strtk.hpp:19872
counting_back_inserter_iterator(const counting_back_inserter_iterator &itr)
Definition: strtk.hpp:3002
void numeric_convert(const std::string &s, T &t, const bool digit_check=false)
Definition: strtk.hpp:12710
const_iterator_ref end() const
Definition: strtk.hpp:2438
bool is_hex_digit(const char c)
Definition: strtk.hpp:14440
sink_type(const std::string &delimiters, const split_options::type &split_option=split_options::compress_delimiters)
Definition: strtk.hpp:14266
bool match_n_consecutive_values(const std::size_t n, find_mode::type mode, Predicate p, Iterator itr, const Iterator end)
Definition: strtk.hpp:14704
std::size_t hamming_distance_elementwise(const Iterator begin1, const Iterator end1, const Iterator begin2, const Iterator end2)
Definition: strtk.hpp:4925
like_impl(const std::string &s)
Definition: strtk.hpp:15201
static type create(const column_list_t &col_list, std::list< T, Allocator > &list)
Definition: strtk.hpp:21720
token_grid(const char *input_buffer, const std::size_t &input_buffer_size, const token_grid::options &options)
Definition: strtk.hpp:6005
void replace(const std::string &pattern, const std::string &replace_pattern)
Definition: strtk.hpp:17208
static token_grid::options default_options()
Definition: strtk.hpp:6810
semantic_action_impl semantic_action(Function &f)
Definition: strtk.hpp:19952
bool operator()(const std::multiset< T, Comparator, Allocator > &multiset) const
Definition: strtk.hpp:7386
translation_table(const std::string &itable, const std::string &otable)
Definition: strtk.hpp:10902
bool operator!() const
Definition: strtk.hpp:20098
void generate_unique_salt()
Definition: strtk.hpp:19320
T & operator[](const std::size_t &index)
Definition: strtk.hpp:877
void clear(const bool force_delete_buffer=false)
Definition: strtk.hpp:6511
std::size_t failure_count() const
Definition: strtk.hpp:22953
bool parse(std::queue< T, Container > &queue) const
Definition: strtk.hpp:5827
bool operator()(const std::pair< InputIterator, InputIterator > &r) const
Definition: strtk.hpp:19900
#define strtk_register_stl_container_to_string_conv_type_tag(T)
Definition: strtk.hpp:15788
bool operator()(std::pair< T1, T2 > &p)
Definition: strtk.hpp:13077
InputIterator contains_all(const InputIterator begin, const InputIterator end) const
Definition: strtk.hpp:19126
bool changed() const
Definition: strtk.hpp:19763
#define strtk_register_byte_type_tag(T)
Definition: strtk.hpp:15716
bool bit_state(const std::size_t &index, const unsigned char *ptr)
Definition: strtk.hpp:4841
column_selector_impl(const column_list_t &column_list, T1 &t0, T1 &t1, T2 &t2, T3 &t3, T4 &t4)
Definition: strtk.hpp:21136
token_grid(const std::string &input_buffer, const std::size_t &input_buffer_size, const token_grid::options &options)
Definition: strtk.hpp:6018
bool parse(Sequence< T, Allocator > &sequence) const
Definition: strtk.hpp:5805
column_selector_base< column_selector_impl< T0, T1, T2, T3, T4, T5, T6, T7, T8 >, 9 > csb_t
Definition: strtk.hpp:21045
void parse(OutputIterator out) const
Definition: strtk.hpp:5637
range_to_ptr_type_iterator(const range_to_ptr_type_iterator &it)
Definition: strtk.hpp:2897
std::size_t split_n(const DelimiterPredicate &delimiter, const Iterator begin, const Iterator end, const std::size_t &token_count, OutputIterator out, const split_options::type &split_option=split_options::default_mode)
Definition: strtk.hpp:3359
Container::value_type value_type
Definition: strtk.hpp:14264
std::string type_name()
Definition: strtk.hpp:16938
counting_back_inserter_iterator & operator++()
Definition: strtk.hpp:3031
static type create(const column_list_t &col_list, Sequence< T, Allocator > &seq)
Definition: strtk.hpp:21714
void compute_block(Iterator itr, std::size_t &length, unsigned int &hash)
Definition: strtk.hpp:19593
fill_array_impl & set(unsigned char *data, const std::size_t &size)
Definition: strtk.hpp:15429
void compute_pod_hash(const char data[], unsigned int &hash)
Definition: strtk.hpp:19540
adapter< T > type(const T *begin, const T *end)
Definition: strtk.hpp:904
bool operator()(const std::string &s) const
Definition: strtk.hpp:19905
#define strtk_parse_col_end()
Definition: strtk.hpp:22333
std::size_t strnlength(const char *s, const std::size_t &n)
Definition: strtk.hpp:1261
bool as_type(T &t) const
Definition: strtk.hpp:17124
void remove_leading_trailing(const std::string &rem_chars, std::string &s)
Definition: strtk.hpp:1518
bool parse_with_index(const std::size_t &col0, const std::size_t &col1, const std::size_t &col2, const std::size_t &col3, const std::size_t &col4, const std::size_t &col5, T0 &t0, T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5) const
Definition: strtk.hpp:5440
row_type row(const unsigned int &row_index) const
Definition: strtk.hpp:6144
static type create(const column_list_t &col_list, Sequence< T, Allocator > &seq)
Definition: strtk.hpp:21609
#define strtk_register_signed_type_tag(T)
Definition: strtk.hpp:15709
void enforce_min_max_column_count(const std::size_t &min_column_count, const std::size_t &max_column_count)
Definition: strtk.hpp:6505
column_selector_impl< T, T, T, T, T, T > type
Definition: strtk.hpp:21709
column_selector_impl(const column_list_t &column_list, T1 &t0, T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5, T6 &t6, T7 &t7, T8 &t8)
Definition: strtk.hpp:21048
base64_to_number_sink & operator=(const base64_to_number_sink &bns)
Definition: strtk.hpp:13976
adapter(T *const begin, T *const end)
Definition: strtk.hpp:837
std::pair< Iterator1, Iterator2 > make_pair(const strtk::range::string &range)
Definition: strtk.hpp:22733
bool operator()(std::set< T, Comparator, Allocator > &set)
Definition: strtk.hpp:13127
#define strk_parse_col_seq
Definition: strtk.hpp:21912
csb_t & operator=(const std::pair< Iterator, Iterator > &r)
Definition: strtk.hpp:20881
bool parse(T0 &t0, T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5, T6 &t6, T7 &t7) const
Definition: strtk.hpp:5547
InputIterator copy_while(Predicate predicate, const InputIterator begin, const InputIterator end, OutputIterator out)
Definition: strtk.hpp:768
void cut_inplace(const std::size_t &r0, const std::size_t &r1, const Iterator begin, const Iterator end)
Definition: strtk.hpp:10861
bool match_n_consecutive(const std::size_t n, find_type::type type, find_mode::type mode, typename details::range_type< Iterator >::type range)
Definition: strtk.hpp:14758
container_adder(std::multiset< T, Comparator, Allocator > &multiset)
Definition: strtk.hpp:8290
double time() const
Definition: strtk.hpp:23296
std::size_t accumulate_column(const std::size_t &col, Predicate p, T &result) const
Definition: strtk.hpp:6617
bool operator()(Sequence< T, Allocator > &seq)
Definition: strtk.hpp:13089
bool operator!=(const char *s, const attribute< std::string > &attrib)
Definition: strtk.hpp:19806
adapter< typename Sequence< T, Allocator >::iterator > type(const Sequence< T, Allocator > &seq)
Definition: strtk.hpp:923
column_selector_impl(const column_list_t &column_list, T1 &t0, T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5)
Definition: strtk.hpp:21115
push_inserter_iterator(Container &container)
Definition: strtk.hpp:2836
range_to_ptr_type_iterator & operator=(const range_to_ptr_type_iterator &it)
Definition: strtk.hpp:2901
compressible_filter(const parameters &p)
Definition: strtk.hpp:19474
bool parse_with_index(const std::size_t &col0, const std::size_t &col1, const std::size_t &col2, const std::size_t &col3, const std::size_t &col4, T0 &t0, T1 &t1, T2 &t2, T3 &t3, T4 &t4) const
Definition: strtk.hpp:5455
bool remove_row_if(const row_range_t &row_range, Predicate predicate)
Definition: strtk.hpp:6373
RandomNumberGenerator void generate_random_values_impl(const std::size_t &count, const T &min, const T &max, OutputIterator out, RandomNumberGenerator &rng, rand_int_type_tag)
Definition: strtk.hpp:11006
Sequence< std::size_t, Allocator > sequence_t
Definition: strtk.hpp:1078
key_map(const Options &)
Definition: strtk.hpp:23124
range_to_type_inserter_iterator & operator=(const range_to_type_inserter_iterator &it)
Definition: strtk.hpp:2578
combination_iterator & operator++()
Definition: strtk.hpp:11844
void create_nway_interleave_table(typename interleave_ary< n >::type table[256])
Definition: strtk.hpp:4715
attribute(const T &t)
Definition: strtk.hpp:19709
bool signed_all_digits_check(Iterator begin, Iterator end)
Definition: strtk.hpp:12638
unsigned long long int usec_time() const
Definition: strtk.hpp:23280
std::size_t offset_splitter(const InputIterator begin, const InputIterator end, const OffsetPredicate &offset, OutputIterator out)
Definition: strtk.hpp:3803
std::pair< string_iterator_type, string_iterator_type > iterator_type
Definition: strtk.hpp:2462
details::expect_impl expect(const std::string &s)
Definition: strtk.hpp:15469
bool imatch(const ext_string &es) const
Definition: strtk.hpp:17134
unsigned int uint32_t
Definition: strtk.hpp:12944
bool negate(T &t, strtk::details::signed_type_tag)
Definition: strtk.hpp:12552
push_inserter_iterator< Container > operator++(int)
Definition: strtk.hpp:2865
functional_inserter_iterator(const functional_inserter_iterator &it)
Definition: strtk.hpp:3065
range_to_type_back_inserter_iterator & operator=(const range_to_type_back_inserter_iterator &it)
Definition: strtk.hpp:2493
bool to_string(std::string &s) const
Definition: strtk.hpp:20152
static ext_string all_digits()
Definition: strtk.hpp:17283
bool be_to_native(T &output)
Definition: strtk.hpp:13199
std::string column_delimiters
Definition: strtk.hpp:5254
double false_positive_probability
Definition: strtk.hpp:18865
void set_bit_low(const std::size_t &index, unsigned char *const ptr)
Definition: strtk.hpp:4873
build_string & operator<<(const T &t)
Definition: strtk.hpp:10532
bool operator()(const std::pair< Iterator, Iterator > &range) const
Definition: strtk.hpp:7272
row_type(const std::size_t &index, const store &dsv_index)
Definition: strtk.hpp:5271
bool operator()(InputIterator begin, InputIterator end)
Definition: strtk.hpp:15206
bool operator()(const Sequence< T, Allocator > &sequence) const
Definition: strtk.hpp:7370
bool operator!() const
Definition: strtk.hpp:19044
uniform_real_rng(const std::size_t &seed=magic_seed, std::size_t pregen=0)
Definition: strtk.hpp:11044
value & operator=(const value &v)
Definition: strtk.hpp:20110
range_to_type_push_inserter_iterator(Container &container)
Definition: strtk.hpp:2641
void reverse(const std_string::iterator_type &range)
Definition: strtk.hpp:22803
column_selector_base< column_selector_impl< T0, T1, T2, T3, T4 >, 5 > csb_t
Definition: strtk.hpp:21133
void assign(const std::string &s)
Definition: strtk.hpp:2420
column_selector_impl(const column_list_t &column_list, T1 &t0, T1 &t1, T2 &t2, T3 &t3)
Definition: strtk.hpp:21156
bool operator()(const T *data, const uint32_t &length, const bool write_length=true)
Definition: strtk.hpp:13438
std::string as_uppercase(const std::string &str)
Definition: strtk.hpp:4618
back_inserter_with_valuetype_iterator operator++(int)
Definition: strtk.hpp:2748
const iterator const_iterator
Definition: strtk.hpp:11772
void remove_empty_strings(Sequence< std::string, Allocator > &seq)
Definition: strtk.hpp:1539
DelimiterPredicate predicate
Definition: strtk.hpp:2373
std::pair< index_t, index_t > row_index_range_t
Definition: strtk.hpp:4960
bool join_column(const std::size_t &col, Predicate p, const std::string &delimiter, std::string &result) const
Definition: strtk.hpp:6764
bool operator()(InputIterator begin, InputIterator end)
Definition: strtk.hpp:15241
std::string source_file() const
Definition: strtk.hpp:6112
std::string as_string() const
Definition: strtk.hpp:5334
column_list_impl< N > column_list_t
Definition: strtk.hpp:20855
std::size_t split_n(const DelimiterPredicate &p, const std::size_t &n, Sequence< std::string, Allocator > &seq, const split_options::type split_option=split_options::default_mode) const
Definition: strtk.hpp:17246
ext_string operator+(const ext_string &s, const T &t)
Definition: strtk.hpp:17333
bool parse(T0 &t0, T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5, T6 &t6) const
Definition: strtk.hpp:5563
std::string swap(const std::string &s, const std::size_t &i0, const std::size_t &i1)
Definition: strtk.hpp:14479
unsigned char operator()(const unsigned char c) const
Definition: strtk.hpp:10920
double desired_false_positive_probability_
Definition: strtk.hpp:19446
bool write_file(const std::string &file_name, const std::string &buffer)
Definition: strtk.hpp:17408
range_to_type_back_inserter_iterator operator++(int)
Definition: strtk.hpp:2543
std::size_t type_length(const T &)
Definition: strtk.hpp:16989
range_to_type_push_inserter_iterator< Container > range_to_type_push_inserter(Container &container)
Definition: strtk.hpp:2696
std::string as_lowercase(const std::string &str)
Definition: strtk.hpp:4611
std::size_t size() const
Definition: strtk.hpp:862
bool operator()(const Sequence< T, Allocator > &sequence) const
Definition: strtk.hpp:7414
ext_string(const range::adapter< char > &r)
Definition: strtk.hpp:17082
bool next_combination(const Iterator first, Iterator k, const Iterator last)
Definition: strtk.hpp:11257
std::size_t accumulate_column(const std::size_t &col, T &result) const
Definition: strtk.hpp:6576
column_selector_impl(const column_list_t &column_list, T0 &t0)
Definition: strtk.hpp:21209
std::size_t count_consecutive_duplicates(const InputIterator begin, const InputIterator end)
Definition: strtk.hpp:3916
std::size_t remove_empty_tokens(const row_range_t &range)
Definition: strtk.hpp:6469
bool validate_column_range(const col_range_t &range) const
Definition: strtk.hpp:5649
bool operator()(const std::multiset< T, Comparator, Allocator > &multiset) const
Definition: strtk.hpp:7296
back_inserter_with_valuetype_iterator & operator++()
Definition: strtk.hpp:2743
column_selector_base< column_selector_impl< T0, T1, T2, T3, T4, T5, T6, T7, T8, T9 >, 10 > csb_t
Definition: strtk.hpp:21022
bool begins_with(const InputIterator pattern_begin, const InputIterator pattern_end, const InputIterator begin, const InputIterator end)
Definition: strtk.hpp:2041
trie::prefix< const char *, ValueType > const_char_ptr
Definition: strtk.hpp:18799
bool operator()(const Iterator begin, const Iterator end) const
Definition: strtk.hpp:7266
column_selector_base< column_selector_impl< T0 >, 1 > csb_t
Definition: strtk.hpp:21206
void delete_if(const Predicate &p, std::multiset< T *, Comparator, Allocator > &cont)
Definition: strtk.hpp:20443
bool parse(const col_range_t &range, std::queue< T, Container > &queue) const
Definition: strtk.hpp:5738
inrange_impl< T > & ref()
Definition: strtk.hpp:15254
column_selector_base< column_selector_impl< T0, T1, T2, T3, T4, T5, T6, T7 >, 8 > csb_t
Definition: strtk.hpp:21068
column_selector_base< column_selector_impl< T0, T1, T2, T3, T4, T5, T6 >, 7 > csb_t
Definition: strtk.hpp:21090
InputIterator contains_none(const InputIterator begin, const InputIterator end) const
Definition: strtk.hpp:19141
bool extract_column(const row_range_t &row_range, const std::size_t &index0, const std::size_t &index1, OutputIterator0 out0, OutputIterator1 out1) const
Definition: strtk.hpp:6238
std::string clone() const
Definition: strtk.hpp:17102
adapter(const std::pair< T *, T * > &r)
Definition: strtk.hpp:842
strtk_register_sequence_type_name(std::vector) strtk_register_sequence_type_name(std
Definition: strtk.hpp:17049
void operator()(const std::pair< Iterator, Iterator > &range) const
Definition: strtk.hpp:7146
void operator()(const std::pair< Iterator, Iterator > &r)
Definition: strtk.hpp:2597
scoped_restore(T &t, const bool restore=true)
Definition: strtk.hpp:19674
unsigned short uint16_t
Definition: strtk.hpp:12945
range_to_type_inserter_iterator & operator++()
Definition: strtk.hpp:2609
void initialize_n_choose_k()
Definition: strtk.hpp:11610
bool imatch(const std::string &s) const
Definition: strtk.hpp:17129
bool operator()(const std::multiset< T, Allocator, Comparator > &multiset)
Definition: strtk.hpp:13547
#define parse_digit_1
bool is_uppercase_letter(const char c)
Definition: strtk.hpp:14430
trie::prefix< const unsigned char *, ValueType > const_uchar_ptr
Definition: strtk.hpp:18801
bool operator()(const InputIterator begin, const InputIterator end)
Definition: strtk.hpp:7103
tokenizer & operator=(const tokenizer &t)
Definition: strtk.hpp:2402
bool concatenate(const std::string &file_name1, const std::string &file_name2, const std::string &output_file_name)
Definition: strtk.hpp:17444
hex_to_string_sink(const hex_to_string_sink &hss)
Definition: strtk.hpp:14048
std::size_t convert_base64_to_bin(const unsigned char *begin, const unsigned char *end, unsigned char *out)
Definition: strtk.hpp:4394
std::deque< iterator_type > token_deque_type
Definition: strtk.hpp:2469
sink_type< std::list< T > > type
Definition: strtk.hpp:14330
unsigned long long int uint64_t
Definition: strtk.hpp:13374
void operator()(const std::pair< Iterator, Iterator > &range)
Definition: strtk.hpp:7119
options & set_row_delimiters(const std::string &delimiters)
Definition: strtk.hpp:5245
std::size_t remove_token_if(const row_range_t &row_range, Predicate predicate)
Definition: strtk.hpp:6421
adapter< const unsigned char > ustring
Definition: strtk.hpp:901
range_to_type_push_inserter_iterator & operator*()
Definition: strtk.hpp:2675
bool operator()(const std::string &str) const
Definition: strtk.hpp:7391
bool parse_columns(const InputIterator begin, const InputIterator end, const std::string &delimiters, const details::column_list_impl< 12 > &column_list, T0 &t0, T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5, T6 &t6, T7 &t7, T8 &t8, T9 &t9, T10 &t10, T11 &t11)
Definition: strtk.hpp:21919
std::pair< char_type *, char_type * > range_type
Definition: strtk.hpp:22890
std::size_t ifind_all(const Iterator pattern_begin, const Iterator pattern_end, const Iterator begin, const Iterator end, OutputIterator out)
Definition: strtk.hpp:1979
range_to_type_inserter_iterator & operator*()
Definition: strtk.hpp:2604
column_selector_impl(const column_list_t &column_list, T1 &t0, T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5, T6 &t6, T7 &t7)
Definition: strtk.hpp:21071
range_to_type_push_inserter_iterator & operator=(const std::pair< Iterator, Iterator > &r)
Definition: strtk.hpp:2659
void convert_to_printable_chars(unsigned char *begin, unsigned char *end)
Definition: strtk.hpp:4497
back_inserter_with_valuetype_iterator< Sequence > back_inserter_with_valuetype(Sequence &sequence_)
Definition: strtk.hpp:2759
multiple_delimiter_predicate(const range::adapter< Type > &r)
Definition: strtk.hpp:996
std::string left_align(const std::size_t &width, const T &t)
Definition: strtk.hpp:14402
bool operator()(InputIterator begin, InputIterator end) const
Definition: strtk.hpp:19891
void copy_if(Predicate predicate, const InputIterator begin, const InputIterator end, OutputIterator out)
Definition: strtk.hpp:750
bool contains(const char *data, const std::size_t &length) const
Definition: strtk.hpp:19120
std::string row_delimiters
Definition: strtk.hpp:5253
int next() const
Definition: strtk.hpp:3687
static type create(const column_list_t &col_list, Sequence< T, Allocator > &seq)
Definition: strtk.hpp:21672
conv_to_ucase_impl(std::string &s)
Definition: strtk.hpp:15382
static std::string transform(const Range &key_range)
Definition: strtk.hpp:23081
range_t range() const
Definition: strtk.hpp:5296
bool operator()(const std::pair< Iterator, Iterator > &range) const
Definition: strtk.hpp:7406
details::enable_if< details::supported_iterator_type< T >::value, T >::type type
Definition: strtk.hpp:283
column_selector_impl(const column_list_t &column_list, T1 &t0, T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5, T6 &t6, T7 &t7, T8 &t8, T9 &t9)
Definition: strtk.hpp:21025
options & set_column_delimiters(const std::string &delimiters)
Definition: strtk.hpp:5239
back_inserter_with_valuetype_iterator(const back_inserter_with_valuetype_iterator &it)
Definition: strtk.hpp:2714
void convert_bin_to_hex(const unsigned char *begin, const unsigned char *end, unsigned char *out)
Definition: strtk.hpp:4161
bool split_pair(const InputIterator begin, const InputIterator end, const Predicate &delimiter, OutputPair &v1, OutputPair &v2)
Definition: strtk.hpp:3839
column_selector_base(const column_list_t &column_list)
Definition: strtk.hpp:20857
void select_1_randomly(const Iterator begin, const Iterator end, OutputIterator out, RandomNumberGenerator &rng)
Definition: strtk.hpp:11233
static type create(const column_list_t &col_list, std::list< T, Allocator > &list)
Definition: strtk.hpp:21783
strtk_register_attribute_type_tag(unsigned short) strtk_register_attribute_type_tag(unsigned int) strtk_register_attribute_type_tag(unsigned long) strtk_register_attribute_type_tag(unsigned long long int) strtk_register_attribute_type_tag(short) strtk_register_attribute_type_tag(int) strtk_register_attribute_type_tag(long) strtk_register_attribute_type_tag(long long) strtk_register_attribute_type_tag(float) strtk_register_attribute_type_tag(double) strtk_register_attribute_type_tag(long double) strtk_register_attribute_type_tag(unsigned char) strtk_register_attribute_type_tag(signed char) strtk_register_attribute_type_tag(char) strtk_register_attribute_type_tag(std
Definition: strtk.hpp:19965
std::vector< iterator_type > token_vector_type
Definition: strtk.hpp:2468
hex_to_number_sink & operator=(const std::string &s)
Definition: strtk.hpp:13910
void enforce_column_count(const std::size_t &column_count)
Definition: strtk.hpp:6489
fill_array_impl & ref()
Definition: strtk.hpp:15424
range_to_type_push_inserter_iterator(const range_to_type_push_inserter_iterator &it)
Definition: strtk.hpp:2645
bool operator()(const std::string &s) const
Definition: strtk.hpp:20140
bool write_pod_proxy(std::ofstream &stream, const T &t)
Definition: strtk.hpp:17533
static type create(const column_list_t &col_list, Sequence< T, Allocator > &seq)
Definition: strtk.hpp:21777
#define strtk_register_inrange_type_tag(T)
Definition: strtk.hpp:15759
bool load_file(const std::string &file_name, std::string &buffer)
Definition: strtk.hpp:17393
std::size_t distance(const std::pair< Iterator, Iterator > &p)
Definition: strtk.hpp:22699
std::size_t max_column_count() const
Definition: strtk.hpp:6127
void operator()(const typename Set::value_type &v)
Definition: strtk.hpp:2796
strtk::tokenizer< string_iterator_type, multiple_char_delimiter_predicate > md_type
Definition: strtk.hpp:2461
bool operator()(const std::string &str)
Definition: strtk.hpp:18533
filter operator|(const filter &a, const filter &b)
Definition: strtk.hpp:19456
bool operator()(const std::string &s, const bool ignore_failures=false)
Definition: strtk.hpp:22948
bool parse(const col_range_t &range, std::priority_queue< T, Container, Comparator > &priority_queue) const
Definition: strtk.hpp:5782
std::size_t split(const DelimiterPredicate &delimiter, const Iterator begin, const Iterator end, OutputIterator out, const split_options::type split_option=split_options::default_mode)
Definition: strtk.hpp:3148
split_options::type row_split_option
Definition: strtk.hpp:5251
bool iends_with(const InputIterator pattern_begin, const InputIterator pattern_end, const InputIterator begin, const InputIterator end)
Definition: strtk.hpp:2129
std::size_t position() const
Definition: strtk.hpp:12973
bool sequential_partition(TransitionPredicate p, Function f)
Definition: strtk.hpp:6805
range_to_ptr_type_iterator(T *pointer, std::size_t &insert_count)
Definition: strtk.hpp:2892
details::like_impl like(const std::string &s)
Definition: strtk.hpp:15479
static bool process(const unsigned char(&c1)[K1], const unsigned char(&c2)[K2])
Definition: strtk.hpp:22663
bool parse(T0 &t0, T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5, T6 &t6, T7 &t7, T8 &t8, T9 &t9) const
Definition: strtk.hpp:5509
bool native_to_le(const T &input)
Definition: strtk.hpp:13593
details::fill_array_impl fill_array(unsigned char *data, const std::size_t &size)
Definition: strtk.hpp:15518
const iterator const_iterator
Definition: strtk.hpp:835
bool operator()(const std::set< T, Comparator, Allocator > &set) const
Definition: strtk.hpp:7288
virtual unsigned long long int size() const
Definition: strtk.hpp:19480
std::size_t for_each_column(const col_range_t &range, Function f) const
Definition: strtk.hpp:5932
void convert_to_uppercase(unsigned char *begin, unsigned char *end)
Definition: strtk.hpp:4554
void make_key_list(const std::map< Key, T, Comparator, MapAllocator > &map, Sequence< Key, SequenceAllocator > &sequence)
Definition: strtk.hpp:20242
iterator & iterator_ref
Definition: strtk.hpp:2376
bool parse_with_index(const std::size_t &col0, const std::size_t &col1, const std::size_t &col2, const std::size_t &col3, const std::size_t &col4, const std::size_t &col5, const std::size_t &col6, const std::size_t &col7, const std::size_t &col8, T0 &t0, T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5, T6 &t6, T7 &t7, T8 &t8) const
Definition: strtk.hpp:5379
std::pair< strtk::util::value, bool > value_t
Definition: strtk.hpp:20901
uintkey_map(const Options &options)
Definition: strtk.hpp:23023
static ext_string all_chars()
Definition: strtk.hpp:17307
unsigned int salt_count_
Definition: strtk.hpp:19440
back_inserter_with_valuetype_iterator(Sequence &sequence)
Definition: strtk.hpp:2710
void mark(const std::size_t &v1, char *v2)
Definition: strtk.hpp:12927
strtk_register_pod_type(bool) strtk_register_pod_type(signed char) strtk_register_pod_type(char) strtk_register_pod_type(short) strtk_register_pod_type(int) strtk_register_pod_type(long int) strtk_register_pod_type(long long int) strtk_register_pod_type(unsigned char) strtk_register_pod_type(unsigned short) strtk_register_pod_type(unsigned int) strtk_register_pod_type(unsigned long int) strtk_register_pod_type(unsigned long long int) strtk_register_pod_type(float) strtk_register_pod_type(double) strtk_register_pod_type(long double) template< typename > struct numeric
Definition: strtk.hpp:15668
bool join_row(const std::size_t &row, Predicate predicate, const char *delimiter, std::string &result)
Definition: strtk.hpp:6682
void set_low_hi(const T &low, const T &hi)
Definition: strtk.hpp:15259
bool operator()(T &output)
Definition: strtk.hpp:13187
bool operator()(T &output, const std::size_t &size)
Definition: strtk.hpp:13244
details::short_string_impl< reader::uint16_t > short_string
Definition: strtk.hpp:13821
counting_back_inserter_iterator & operator=(const counting_back_inserter_iterator &itr)
Definition: strtk.hpp:3006
std::size_t ifind(const std::string &pattern, const std::string &data)
Definition: strtk.hpp:1965
bool reset(std::size_t &v1, char *&v2)
Definition: strtk.hpp:12917
T as_type() const
Definition: strtk.hpp:17118
const T & previous() const
Definition: strtk.hpp:19778
std::pair< index_t, index_t > row_range_t
Definition: strtk.hpp:4962
DelimiterPredicate predicate_type
Definition: strtk.hpp:2458
bool operator()(const Sequence< T, Allocator > &sequence) const
Definition: strtk.hpp:7325
range_to_type_inserter_iterator operator++(int)
Definition: strtk.hpp:2614
bool read_pod_proxy(std::ifstream &stream, T &t)
Definition: strtk.hpp:17526
bool operator==(const char *s, const attribute< std::string > &attrib)
Definition: strtk.hpp:19801
sink_type< std::vector< T > > type
Definition: strtk.hpp:14328
bool signed_numeric_convert(const std::string &s, T &t, const bool digit_check=false)
Definition: strtk.hpp:12761
bool read_at_offset(const std::string &file_name, const std::size_t &offset, std::string &buffer, const std::size_t &buffer_size)
Definition: strtk.hpp:17941
inserter_with_valuetype_iterator & operator*()
Definition: strtk.hpp:2801
void copy_n(InputIterator itr, std::size_t n, OutputIterator out)
Definition: strtk.hpp:736
void insert(const T &t)
Definition: strtk.hpp:19068
bool operator()(const char &c) const
Definition: strtk.hpp:1050
const_iterator & const_iterator_ref
Definition: strtk.hpp:2377
const T & operator()() const
Definition: strtk.hpp:19738
std::pair< index_t, index_t > col_range_t
Definition: strtk.hpp:4963
std::size_t index() const
Definition: strtk.hpp:5306
std::deque< range_t > token_list_t
Definition: strtk.hpp:4959
bool parse(std::stack< T, Container > &stack) const
Definition: strtk.hpp:5833
bool operator()(strtk::binary::writer &writer)
Definition: strtk.hpp:18880
tokenizer::iterator_type iterator_type
Definition: strtk.hpp:2465
std::size_t type
Definition: strtk.hpp:3119
unsigned long long int n_choose_k(const unsigned long long int &n, const unsigned long long int &k)
Definition: strtk.hpp:11527
bool operator()(const T *data, const uint16_t &length, const bool write_length=true)
Definition: strtk.hpp:13461
bool le_to_native(T &output)
Definition: strtk.hpp:13213
unsigned long long int projected_element_count_
Definition: strtk.hpp:19443
unsigned long long int projected_element_count
Definition: strtk.hpp:18860
bool operator!() const
Definition: strtk.hpp:3672
token_grid(const std::string &file_name, const std::string &column_delimiters=",|;\t", const std::string &row_delimiters="\n\r")
Definition: strtk.hpp:6031
unsigned char * write_pod(unsigned char *data, const T1 &t1, const T2 &t2, const T3 &t3, const T4 &t4, const T5 &t5, const T6 &t6, const T7 &t7, const T8 &t8, const T9 &t9, const T10 &t10, const T11 &t11, const T12 &t12)
Definition: strtk.hpp:18191
bool parse(T0 &t0, T1 &t1, T2 &t2) const
Definition: strtk.hpp:5614
combination_iterator(const std::string &str)
Definition: strtk.hpp:11827
static bool process(ptr, ptr)
Definition: strtk.hpp:22669
bool parse_with_index(const std::size_t &col0, const std::size_t &col1, const std::size_t &col2, const std::size_t &col3, T0 &t0, T1 &t1, T2 &t2, T3 &t3) const
Definition: strtk.hpp:5469
bool copy_file(const std::string &src_file_name, const std::string &dest_file_name)
Definition: strtk.hpp:17413
filter operator&(const filter &a, const filter &b)
Definition: strtk.hpp:19449
bool parse_nan(Iterator &itr, const Iterator end, T &t)
Definition: strtk.hpp:16433
#define strtk_register_trim_type_tag(T)
Definition: strtk.hpp:15763
void assign(const Iterator begin, const Iterator end)
Definition: strtk.hpp:2425
static bool cmp(ptr c1, ptr c2)
Definition: strtk.hpp:22634
sink_type< Container > & reference()
Definition: strtk.hpp:14315
functional_inserter_iterator & operator=(const functional_inserter_iterator &it)
Definition: strtk.hpp:3069
std::size_t for_each_token(const std::string &buffer, Tokenizer &tokenizer, Function function)
Definition: strtk.hpp:76
range_to_type_inserter_iterator(const range_to_type_inserter_iterator &it)
Definition: strtk.hpp:2574
inserter_with_valuetype_iterator & operator=(const inserter_with_valuetype_iterator &itr)
Definition: strtk.hpp:2781
void lexicographically_canonicalize(Iterator begin, Iterator end)
Definition: strtk.hpp:4032
bool operator!() const
Definition: strtk.hpp:13384
range_to_type_push_inserter_iterator operator++(int)
Definition: strtk.hpp:2685
string_condition(condition_type cond_type, const std::string &str)
Definition: strtk.hpp:18501
ValueValidator value_validator_type
Definition: strtk.hpp:23121
virtual bool compute_optimal_parameters()
Definition: strtk.hpp:18904
details::conv_to_lcase_impl as_lcase(std::string &s)
Definition: strtk.hpp:15508
bool extract_column(const row_range_t &row_range, const std::size_t &index0, const std::size_t &index1, const std::size_t &index2, const std::size_t &index3, const std::size_t &index4, OutputIterator0 out0, OutputIterator1 out1, OutputIterator2 out2, OutputIterator3 out3, OutputIterator4 out4) const
Definition: strtk.hpp:6328
bool set_array(unsigned char(&a)[N], const std::string &s, const bool pad=false, const unsigned char padding= '0')
Definition: strtk.hpp:22776
void insert(prefix< std::string::iterator, Value > &trie, const char *key, const Value &value=Value(0))
Definition: strtk.hpp:18754
static bool process(const char *c1, const char *c2)
Definition: strtk.hpp:22657
sink_type< std::multiset< T > > type
Definition: strtk.hpp:14332
bool operator()(const std::set< T, Comparator, Allocator > &set) const
Definition: strtk.hpp:7422
bool cmpimpl(ptr c1, ptr c2)
Definition: strtk.hpp:22628
container_adder(std::priority_queue< T, Container, Comparator > &pq)
Definition: strtk.hpp:8295
bool parse_inf(Iterator &itr, const Iterator end, T &t, bool negative)
Definition: strtk.hpp:16455
combination_iterator(Sequence< T, Allocator > &seq)
Definition: strtk.hpp:11837
bool find(prefix< std::string::const_iterator, Value > &trie, const char *key, Value &v)
Definition: strtk.hpp:18770
#define strtk_register_hex_number_type_tag(T)
Definition: strtk.hpp:15720
void remove_row(const std::size_t &index)
Definition: strtk.hpp:6364
bound_range(Function f, Iterator first, Iterator last)
Definition: strtk.hpp:11448
bool operator()(std::multiset< T, Allocator, Comparator > &multiset)
Definition: strtk.hpp:13151
std::size_t convert_bin_to_base64(const unsigned char *begin, const unsigned char *end, unsigned char *out)
Definition: strtk.hpp:4333
bool operator==(const semantic_action_impl &sa) const
Definition: strtk.hpp:19883
std::size_t split(const DelimiterPredicate &p, Sequence< std::string, Allocator > &seq, const split_options::type split_option=split_options::default_mode) const
Definition: strtk.hpp:17227
container_adder(std::queue< T, Container > &queue)
Definition: strtk.hpp:8300
static type create(const column_list_t &col_list, std::list< T, Allocator > &list)
Definition: strtk.hpp:21657
bool operator()(const std::multiset< T, Comparator, Allocator > &multiset) const
Definition: strtk.hpp:7474
bool register_keyvalue(const typename KeyValueMap::key_type &key, T &t)
Definition: strtk.hpp:22903
inserter_with_valuetype_iterator operator++(int)
Definition: strtk.hpp:2811
bool operator()(const T &input)
Definition: strtk.hpp:13575
bool add(std::pair< InputIterator, InputIterator > &range) const
Definition: strtk.hpp:8316
range_type< Iterator >::type find_atleast_n_consecutive_values(const std::size_t n, Predicate p, Iterator itr, const Iterator end)
Definition: strtk.hpp:14587
token_grid(const char *input_buffer, const std::size_t &input_buffer_size, const std::string &column_delimiters=",|;\t", const std::string &row_delimiters="\n\r")
Definition: strtk.hpp:6064
ext_string & to_lowercase()
Definition: strtk.hpp:17139
const std::string & as_string() const
Definition: strtk.hpp:17107
std::size_t for_each_line_conditional(std::istream &stream, Function function, const std::size_t &buffer_size=one_kilobyte)
Definition: strtk.hpp:153
const char * position_ptr() const
Definition: strtk.hpp:13404
ext_string & to_uppercase()
Definition: strtk.hpp:17145
const char * position_ptr() const
Definition: strtk.hpp:12978
std::string as_string(const adapter< const char > &a)
Definition: strtk.hpp:928
ext_string(const std::string &s)
Definition: strtk.hpp:17074
std::pair< InputIterator, InputIterator > iterator_type
Definition: strtk.hpp:21839
bool extract_column(const row_range_t &row_range, const std::size_t &index0, const std::size_t &index1, const std::size_t &index2, OutputIterator0 out0, OutputIterator1 out1, OutputIterator2 out2) const
Definition: strtk.hpp:6263
static type create(const column_list_t &col_list, Sequence< T, Allocator > &seq)
Definition: strtk.hpp:21798
bool convert_hex_to_bin(const unsigned char *begin, const unsigned char *end, unsigned char *out)
Definition: strtk.hpp:4243
bool operator()(const std::string &str) const
Definition: strtk.hpp:7301
range_to_type_back_inserter_iterator< Sequence > range_to_type_back_inserter(Sequence &sequence)
Definition: strtk.hpp:2554
std::size_t split_n(const DelimiterPredicate &p, const std::size_t &n, OutputIterator out, const split_options::type split_option=split_options::default_mode) const
Definition: strtk.hpp:17235
bool operator()(const std::pair< Iterator, Iterator > &range) const
Definition: strtk.hpp:7450
conv_to_lcase_impl(std::string &s)
Definition: strtk.hpp:15355
void set_bit_high(const std::size_t &index, unsigned char *const ptr)
Definition: strtk.hpp:4857
iexpect_impl(const std::string &s)
Definition: strtk.hpp:15169
bool type_to_string(const T &t, std::string &s)
Definition: strtk.hpp:371
unsigned long long int uint64_t
Definition: strtk.hpp:12947
bool parse(T0 &t0, T1 &t1, T2 &t2, T3 &t3) const
Definition: strtk.hpp:5604
bool operator()(const std::multiset< T, Comparator, Allocator > &multiset) const
Definition: strtk.hpp:7430
unsigned int index_t
Definition: strtk.hpp:4957
tokenizer(const std::string &s, const DelimiterPredicate &predicate, const tokenize_options::type tokenize_options=tokenize_options::default_mode)
Definition: strtk.hpp:2391
const cell_type * table() const
Definition: strtk.hpp:19228
void parse_checked(std::multiset< T, Comparator, Allocator > &multiset) const
Definition: strtk.hpp:5906
T min_of_cont(const Sequence< T, Allocator > &sequence)
Definition: strtk.hpp:3935
fill_array_impl & set(char *data, const std::size_t &size)
Definition: strtk.hpp:15436
std::size_t high_bit_count(const unsigned char c)
Definition: strtk.hpp:4772
sequence_t::const_iterator end_
Definition: strtk.hpp:1104
bool operator!=(const TConvertibleType &t)
Definition: strtk.hpp:19728
std::size_t operator()(std::ofstream &stream)
Definition: strtk.hpp:13568
Iterator inc(Iterator itr, const std::size_t &n)
Definition: strtk.hpp:21590
bool parse(const col_range_t &range, Sequence< T, Allocator > &sequence) const
Definition: strtk.hpp:5671
std::size_t remove_leading(Predicate predicate, Iterator begin, Iterator end)
Definition: strtk.hpp:1454
writer(T *buffer, const std::size_t &buffer_length)
Definition: strtk.hpp:13377
index_remover_impl(const sequence_t &sequence)
Definition: strtk.hpp:1079
void translate_inplace(const translation_table &trans_table, std::string &s)
Definition: strtk.hpp:10937
void set_value(const std::string &s)
Definition: strtk.hpp:15155
const iterator const_iterator
Definition: strtk.hpp:2375
combination_iterator operator++(int)
Definition: strtk.hpp:11856
bound_range_conditional(Function f, Iterator first, Iterator last)
Definition: strtk.hpp:11473
bool operator()(InputIterator begin, InputIterator end)
Definition: strtk.hpp:15415
column_selector_base< column_selector_impl< T0, T1 >, 2 > csb_t
Definition: strtk.hpp:21189
std::size_t split(const DelimiterPredicate &p, OutputIterator out, const split_options::type split_option=split_options::default_mode) const
Definition: strtk.hpp:17217
static bool process(details::ptr c1, details::ptr c2)
Definition: strtk.hpp:22651
column_selector_impl(const column_list_t &column_list, T0 &t0, T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5, T6 &t6, T7 &t7, T8 &t8, T9 &t9, T10 &t10, T11 &t11)
Definition: strtk.hpp:20974
bool string_to_type_converter_impl_ref(Iterator &itr, const Iterator end, T &result, signed_type_tag)
Definition: strtk.hpp:16377
strtk_register_unsigned_type_tag(unsigned short) strtk_register_unsigned_type_tag(unsigned int) strtk_register_unsigned_type_tag(unsigned long) strtk_register_unsigned_type_tag(unsigned long long int) strtk_register_signed_type_tag(short) strtk_register_signed_type_tag(int) strtk_register_signed_type_tag(long) strtk_register_signed_type_tag(long long) strtk_register_real_type_tag(float) strtk_register_real_type_tag(double) strtk_register_real_type_tag(long double) strtk_register_byte_type_tag(unsigned char) strtk_register_byte_type_tag(signed char) strtk_register_byte_type_tag(char) strtk_register_hex_number_type_tag(hex_to_number_sink< short >) strtk_register_hex_number_type_tag(hex_to_number_sink< int >) strtk_register_hex_number_type_tag(hex_to_number_sink< long >) strtk_register_hex_number_type_tag(hex_to_number_sink< unsigned short >) strtk_register_hex_number_type_tag(hex_to_number_sink< unsigned int >) strtk_register_hex_number_type_tag(hex_to_number_sink< unsigned long >) strtk_register_hex_number_type_tag(hex_to_number_sink< unsigned long long int >) strtk_register_base64_type_tag(base64_to_number_sink< short >) strtk_register_base64_type_tag(base64_to_number_sink< int >) strtk_register_base64_type_tag(base64_to_number_sink< long >) strtk_register_base64_type_tag(base64_to_number_sink< unsigned short >) strtk_register_base64_type_tag(base64_to_number_sink< unsigned int >) strtk_register_base64_type_tag(base64_to_number_sink< unsigned long >) strtk_register_base64_type_tag(base64_to_number_sink< unsigned long long int >) strtk_register_stdstring_range_type_tag(std
Definition: strtk.hpp:15806
bool find_prefix(const key_iterator_t begin, const key_iterator_t end) const
Definition: strtk.hpp:18717
std::list< iterator_type > token_list_type
Definition: strtk.hpp:2470
static ext_string all_letters()
Definition: strtk.hpp:17289
bool convert_string_range(const std::pair< std::string::const_iterator, std::string::const_iterator > &range, T &t)
Definition: strtk.hpp:7080
bool operator()(const std::multiset< T, Comparator, Allocator > &multiset) const
Definition: strtk.hpp:7341
row_range_t range(std::size_t lower_bound, std::size_t upper_bound=std::numeric_limits< std::size_t >::max()) const
Definition: strtk.hpp:5187
tuple f
First do the data loading part.
column_selector_iterator_impl(const details::column_list_impl< N > &column_list, iterator_type(&token_list)[N])
Definition: strtk.hpp:21842
void replace_pattern(const std::string &s, const std::string &p, const std::string &r, std::string &n)
Definition: strtk.hpp:1608
sink_type< std::set< T > > type
Definition: strtk.hpp:14331
#define strtk_parse_col_token(Index)
Definition: strtk.hpp:21894
std::size_t split_regex_n(const boost::regex &delimiter_expression, const InputIterator begin, const InputIterator end, const std::size_t &token_count, OutputIterator out, const regex_match_mode::type mode=regex_match_mode::match_all)
Definition: strtk.hpp:3589
parser(const Options &opts)
Definition: strtk.hpp:22893
split_options::type column_split_option
Definition: strtk.hpp:5252
bool operator()(const std::pair< Iterator, Iterator > &range) const
Definition: strtk.hpp:7317
bool parse(T0 &t0, T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5) const
Definition: strtk.hpp:5578
column_selector_impl(const column_list_t &column_list, T1 &t0, T1 &t1)
Definition: strtk.hpp:21192
#define strtk_register_real_type_tag(T)
Definition: strtk.hpp:15713
bool operator()(const T &output)
Definition: strtk.hpp:13193
bool read_from_file(const std::string &file_name)
Definition: strtk.hpp:19272
#define strtk_register_pair_to_ostream(Iterator)
Definition: strtk.hpp:23194
std::pair< Iterator1, Iterator2 > make_pair(const std::string &s)
Definition: strtk.hpp:22705
col_range_t range(const std::size_t &lower_bound, const std::size_t &upper_bound=std::numeric_limits< std::size_t >::max()) const
Definition: strtk.hpp:5659
options & set_column_split_option(const split_options::type &option)
Definition: strtk.hpp:5227
unsigned char * read_pod(unsigned char *data, T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5, T6 &t6, T7 &t7, T8 &t8, T9 &t9, T10 &t10, T11 &t11, T12 &t12)
Definition: strtk.hpp:17960
bool join_row(const std::size_t &row, const std::string &delimiter, std::string &result)
Definition: strtk.hpp:6624
functional_inserter_iterator & operator++()
Definition: strtk.hpp:3096
std::string make_string(const unsigned char(&s)[N], const std::size_t &length=N)
Definition: strtk.hpp:22741
bool operator()(const Range &key_range, const Range &value_range)
Definition: strtk.hpp:23131
void remaining_string(const std::size_t &index, const std::string &str, std::string &result)
Definition: strtk.hpp:14413
bool random_combination(const Iterator begin, const Iterator end, std::size_t set_size, RandomNumberGenerator &rng, OutputIterator out)
Definition: strtk.hpp:11142
void extract_column_checked(const std::size_t &index, std::set< T, Comparator, Allocator > &set) const
Definition: strtk.hpp:6194
bool seek(const int &n_bytes)
Definition: strtk.hpp:13000
range_t token(const std::size_t &index) const
Definition: strtk.hpp:5301
bool operator!() const
Definition: strtk.hpp:12958
fill_array_impl & set_size(const std::size_t &size)
Definition: strtk.hpp:15455
std::string right_align(const std::size_t &width, const T &t)
Definition: strtk.hpp:14396
details::trim_impl< T > trim_trailing(const std::string &rem_chars, T &t)
Definition: strtk.hpp:15503
column_selector_impl(const column_list_t &column_list, T0 &t0, T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5, T6 &t6, T7 &t7, T8 &t8, T9 &t9, T10 &t10)
Definition: strtk.hpp:21000
std::size_t remove_empty_tokens()
Definition: strtk.hpp:6474
push_inserter_iterator< Container > & operator*()
Definition: strtk.hpp:2855
bool remove_row_if(Predicate predicate)
Definition: strtk.hpp:6415
std::size_t accumulate_column(const std::size_t &col, const row_range_t &row_range, Predicate p, T &result) const
Definition: strtk.hpp:6582
filter operator^(const filter &a, const filter &b)
Definition: strtk.hpp:19463
ValueType value_t
Definition: strtk.hpp:18653
std::size_t raw_length() const
Definition: strtk.hpp:5316
bool operator()(const Sequence< T, Allocator > &sequence) const
Definition: strtk.hpp:7458
bool operator()(const std::string &str) const
Definition: strtk.hpp:7346
bool file_exists(const std::string &file_name)
Definition: strtk.hpp:17370
hex_to_string_sink & operator=(const hex_to_string_sink &hss)
Definition: strtk.hpp:14053
static ext_string all_uppercase_letters()
Definition: strtk.hpp:17301
expect_impl(const std::string &s)
Definition: strtk.hpp:15137
trie::prefix< unsigned char *, ValueType > uchar_ptr
Definition: strtk.hpp:18800
void enforce_min_max_column_count(const row_range_t &row_range, const std::size_t &min_column_count, const std::size_t &max_column_count)
Definition: strtk.hpp:6494
bool operator()(const T *data, const uint64_t &length, const bool write_length=true)
Definition: strtk.hpp:13455
T max_of_cont(const Sequence< T, Allocator > &sequence)
Definition: strtk.hpp:3959
options(split_options::type sro, split_options::type sco, const std::string &rd, const std::string &cd, const bool support_dq=false)
Definition: strtk.hpp:5215
bool operator()(const std::set< T, Comparator, Allocator > &set) const
Definition: strtk.hpp:7466
void process(const std::pair< Iterator, Iterator > &r)
Definition: strtk.hpp:20926
bool imatch(const InputIterator begin1, const InputIterator end1, const InputIterator begin2, const InputIterator end2)
Definition: strtk.hpp:1860
static type create(const column_list_t &col_list, std::list< T, Allocator > &list)
Definition: strtk.hpp:21762
static type create(const column_list_t &col_list, Sequence< T, Allocator > &seq)
Definition: strtk.hpp:21756
bool ibegins_with(const InputIterator pattern_begin, const InputIterator pattern_end, const InputIterator begin, const InputIterator end)
Definition: strtk.hpp:2069
void parse_checked(OutputIterator out) const
Definition: strtk.hpp:5871
std::string as_string() const
Definition: strtk.hpp:10543
bool operator()(const std::pair< T1, T2 > &p)
Definition: strtk.hpp:13473
void fill(std::string &s, const std::string::value_type v)
Definition: strtk.hpp:22831
unsigned long long int maximum_size
Definition: strtk.hpp:18851
single_delimiter_predicate(const T &d)
Definition: strtk.hpp:947
bool read_line_as_value(std::istream &stream, T &t, const std::size_t &buffer_size=one_kilobyte)
Definition: strtk.hpp:218
void extract_unique(const InputIterator begin, const InputIterator end, OutputIterator out)
Definition: strtk.hpp:800
bool operator!=(const combination_iterator &itr) const
Definition: strtk.hpp:11884
column_selector_impl< T, T, T, T, T, T, T, T > type
Definition: strtk.hpp:21751
bool combine_discontinuous_conditional(Iterator first1, Iterator last1, typename std::iterator_traits< Iterator >::difference_type d1, Iterator first2, Iterator last2, typename std::iterator_traits< Iterator >::difference_type d2, Function &f, typename std::iterator_traits< Iterator >::difference_type d=0)
Definition: strtk.hpp:11400
unsigned int bloom_type
Definition: strtk.hpp:18960
T operator[](const std::size_t &index) const
Definition: strtk.hpp:5279
back_inserter_with_valuetype_iterator & operator=(const back_inserter_with_valuetype_iterator &it)
Definition: strtk.hpp:2718
details::short_string_impl< reader::uint8_t > pascal_string
Definition: strtk.hpp:13822